Solved

SQL Add Field

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

15 Experts available now in Live!

Get 1:1 Help Now