Solved

SQL Add Field

Posted on 2008-10-21
4
470 Views
Last Modified: 2012-05-05
Dear Expert,

I have a database file which hold around 10 fields. And now would like to add one more field by SQL statement. Can I do that like follow?

Create Tabe Test (Test Int);

Seems wrong, because it didnt allow me to go ahead...(I am using the Access)

Thanks.

Ricky.
0
Comment
Question by:Rickyyy
  • 2
  • 2
4 Comments
 
LVL 30

Accepted Solution

by:
hnasr earned 125 total points
ID: 22770265
This code adds field c3 to table t1.

Private Sub Command19_Click()
    Dim dbs As Database
    Set dbs = CurrentDb
   
    dbs.Execute "ALTER TABLE t1 " _
        & "ADD COLUMN c3 CHAR(20);"
End Sub
0
 
LVL 30

Expert Comment

by:hnasr
ID: 22770287
If table is in a different database, use:
Set dbs = OpenDatabase("NameOfDatabase.mdb")

When you finish the code,
dbs.Close
0
 

Author Comment

by:Rickyyy
ID: 22774245
Run-time error '3293':
Syntax error in ALTER TABLE statement.
'------------------------------------------
Public Function Insert()
    Dim dbs As Database
    Set dbs = CurrentDb
   
    dbs.Execute "ALTER TABLE RawData " _
        & "ADD COLUMN Test INT(2);"
End Function
'------------------------------------------
any problem on it???
0
 

Author Closing Comment

by:Rickyyy
ID: 31508445
Finally, I am using the SQL statement to add the new column in tables.

ALTER TABLE rawdata ADD test int

But anyway, thanks again.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question