By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,778 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,778 IT Pros & Developers. It's quick & easy.

Create Table

P: 20
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.
Jun 12 '07 #1
Share this Question
Share on Google+
5 Replies


NeoPa
Expert Mod 15k+
P: 31,489
Search in help under CREATE TABLE statement and ALTER TABLE statement.
Jun 12 '07 #2

P: 49
Search in help under CREATE TABLE statement and ALTER TABLE statement.

Expand|Select|Wrap|Line Numbers
  1.  
  2. CREATE TABLE employee
  3.  
  4. (id  COUNTER PRIMARY KEY,
  5. name VARCHAR(30),
  6. address1 VARCHAR(40),
  7. address2 VARCHAR(40),
  8. Town VARCHAR(30),
  9. postcode VARCHAR(10),
  10. phone INTEGER
  11.  
  12. )
  13.  
  14.  
Try this

gareth
Jun 13 '07 #3

P: 20
Where do you write SQL code?
Jun 16 '07 #4

P: 49
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
Jun 16 '07 #5

NeoPa
Expert Mod 15k+
P: 31,489
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 :
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdButton_Click()
  2.   Dim strSQL As String
  3.  
  4.   strSQL = "CREATE TABLE tblEmployee (" & _
  5.            "id  COUNTER PRIMARY KEY, " & _
  6.            "name VARCHAR(30), " & _
  7.            "address1 VARCHAR(40), " & _
  8.            "address2 VARCHAR(40), " & _
  9.            "Town VARCHAR(30), " & _
  10.            "postcode VARCHAR(10), " & _
  11.            "phone INTEGER)"
  12.     Call DoCmd.RunSQL(strSQL)
  13. End Sub
Jun 17 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.