Create Table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Asad Asad
    New Member
    • May 2007
    • 20

    Create Table

    I wants to create a table in Ms Access By using SQL statment.
    Please tell me how can I do this?
    And then after creating I wants to add a column in it by using SQL.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32636

    #2
    Search in help under CREATE TABLE statement and ALTER TABLE statement.

    Comment

    • garethfx
      New Member
      • Apr 2007
      • 49

      #3
      Originally posted by NeoPa
      Search in help under CREATE TABLE statement and ALTER TABLE statement.

      Code:
      CREATE TABLE employee
      
      (id  COUNTER PRIMARY KEY,
      name VARCHAR(30),
      address1 VARCHAR(40),
      address2 VARCHAR(40),
      Town VARCHAR(30),
      postcode VARCHAR(10),
      phone INTEGER
      
      )
      Try this

      gareth

      Comment

      • Asad Asad
        New Member
        • May 2007
        • 20

        #4
        Where do you write SQL code?

        Comment

        • garethfx
          New Member
          • Apr 2007
          • 49

          #5
          Originally posted by Asad Asad
          Where do you write SQL code?
          As you seem (like me ) very new to SQL then the easiest way to start this off is:

          1 - open the access DB you are workig on
          2 - click in to the QUERY OBJECT
          3 - DOUBLE click on Create Query In Design View
          4 - Close the SHOW TABLE Box that appears
          5 - In VIEW change to SQL or if SQL appears in the top left Menu bar click that (depends on Access version you are using)

          6 - You will be presented with SQL View and should have "SELECT;" already in place
          7 - remove this and add your code

          8 - save the query as what ever name and run it

          If you have input correctly you'll have your table there. If you click again Access will tell you you already have the desired table.

          Hope that helps you start off ground up

          Gareth

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32636

            #6
            Originally posted by Asad Asad
            Where do you write SQL code?
            Another way of using SQL code (other than the very helpful point made by GarethFX), is to create or use a string in VBA and pass it to the DoCmd.RunSQL procedure :
            Code:
            Private Sub cmdButton_Click()
              Dim strSQL As String
            
              strSQL = "CREATE TABLE tblEmployee (" & _
                       "id  COUNTER PRIMARY KEY, " & _
                       "name VARCHAR(30), " & _
                       "address1 VARCHAR(40), " & _
                       "address2 VARCHAR(40), " & _
                       "Town VARCHAR(30), " & _
                       "postcode VARCHAR(10), " & _
                       "phone INTEGER)"
                Call DoCmd.RunSQL(strSQL)
            End Sub

            Comment

            Working...