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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL question using ASP/ADO 2

Status
Not open for further replies.

kor

Programmer
Mar 15, 2001
27
US
objConn.Execute("CREATE TABLE Users")
objConn.Execute("ALTER TABLE Users ADD COLUMN userID INTEGER UNIQUE")
objConn.Execute("ALTER TABLE Users ADD COLUMN userFirstName VARCHAR[50]")
objConn.Execute("ALTER TABLE Users ADD COLUMN userLastName VARCHAR[50]")
objConn.Execute("ALTER TABLE Users ADD COLUMN userInfo TEXT")

This is a simplified version of my table. The database is Access 97, code is ASP/ADO. What I want to know is how to modify the table with keywords so I can write an insert query with just the name fields and have the userID field auto increment and the userInfo field default to NULL. A sample of that query would be useful as well. Thanks for your help.

Oh, and I'd also like to know how include the field descriptions in the create table command so I don't have to use all these alter table statements. They make my code look less concise.
 
objConn.Execute("CREATE TABLE Users (userID counter, userFirstName text(50), userLastName text(50), userInfo TEXT(255), constraint PK_Users primary key (UserID))")

That should work for Access backends .. added a primary key for you. Because UserID is now a counter (Autonumber in Access), if you don't try to assign it a value in an insert (ie just ignore it), it will automatically become the next number.

Ben
+61 403 395 052
 
Qaroven! Thanks a bunch. I've been looking for a way to create an autonumber field programmatically for a very long time. You've got my vote! Yours,

Rob.
 
Same here. Great tip! I was about to jump knee deep into creating tables and that was something I had wondered about but hadn't investigated thoroughly yet. You just saved me a lot of time. THANKS!!!
Ed (RoadRacer) Holguin

"I Hate Computers!"
 
Another small tip for ya's then w.r.t. create table statements in Access .

Yes/No - True/False - On/Off datatype in Access is called a bit field when you define it in a create table statement. Ben
+61 403 395 052
 
Cool. I almost had to resort to ADOX to make that happen. Yours,

Rob.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top