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

ASP - Creating a table using SQL with an auto incriment long 1

Status
Not open for further replies.

kingkeith

Programmer
May 8, 2002
18
GB
Can anyone tell me how to make a table using SQL with a long which is auto incrimented?
I am making a guestbook that many people can use and admin, so I create a new table for every person that registers.
I want the ID to be a long, and an auto incriment. This will let people admin their guestbook. (I need the id for editing and deleting records)

My current code is:

(I have used guestbook as my example - but it is really my new guys username (as this is in my register.asp))

objConn.Execute "CREATE TABLE [guestbook]" ' create the table
objConn.Execute "ALTER TABLE [guestbook] ADD COLUMN [id] INTEGER IDENTITY" 'add the ID field - this should be a long which auto incriments
objConn.Execute "ALTER TABLE [guestbook] ADD COLUMN [name] VARCHAR(255) NOT NULL" 'add the name field
objConn.Execute "ALTER TABLE [guestbook] ADD COLUMN VARCHAR(255) NOT NULL" 'add the email field
objConn.Execute "ALTER TABLE [guestbook] ADD COLUMN [url] VARCHAR(255) NULL" 'add the url field
objConn.Execute "ALTER TABLE [guestbook] ADD COLUMN [comment] TEXT NOT NULL" 'add the comment field
objConn.Execute "CREATE INDEX [PrimaryKey] ON [guestbook] (ID)" 'create the primary key

This creates the table fine, and people can submit their comments and view the guestbook ok, but its just the admin that doesnt work properly...

Thanks in advance

Keith
 
Instead of doing multiple different CREATE/ALTER statements, use one statement to create the table:

objConn.Execute "CREATE TABLE [guestbook] ([id] INT IDENTITY PRIMARY KEY, [name] VARCHAR(255) NOT NULL, VARCHAR(255) NOT NULL, [url] VARCHAR(255) NULL, [comment] TEXT NOT NULL)"

This, as written, will create the table, add the columns, and make the [id] column the Primary Key.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top