Solved

SQL Add Field

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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

Suggested Solutions

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

679 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