Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql help

Status
Not open for further replies.

TRYP

Programmer
Jun 20, 2000
136
US
i have an access 2000 database and i want to use an alter table statement.

I want to add a boolean field with a deafault set to true.

can access do this or should i pick another database to do this simple process ???

tryp
 
I have no clue how you would do that using SQL, but it's fairly straight-forward to do using DAO. Here's a quick example (untested):
Code:
'tbl is a TableDef object set to the table you need to modify.
dim fld as DAO.Field
Set fld = tbl.CreateField("myfield", dbBoolean)
fld.DefaultValue = True
tbl.Fields.Append fld
 
Thank you

However I do want to do it with SQL only.
Is it possible??

TRYP
 
...

Dim Cnn As New ADODB.Connection
Dim cnnString As String
Dim sqlQuery As String

...
cnnString = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=<DatabasePath>&quot;
Cnn.Open cnnString
...
sqlQuery = &quot;ALTER TABLE <TableName> ADD <FieldName> <FieldType> DEFAULT <Value>&quot;

Cnn.Execute sqlQuery
...

This is supposed to work...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top