Solved

SQL Add Field

Posted on 2008-10-21
4
469 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

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

867 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now