February 17, 2004 at 6:34 am
Dear all,
I would like to create set of SQL statement to generate auto ID when new data is inserted. How I can do this in SQL Server 2000.
Thanks you for reply!!!
February 17, 2004 at 6:54 am
Add a IDENTITY column, sql will automatically increment the column when new rows are inserted.
Far away is close at hand in the images of elsewhere.
Anon.
February 18, 2004 at 9:24 am
David Burrows, Thanks you for reply!!
I still have question about using IDENTITY column. What data type does it return when I use it?? Can I use this to auto generate string value??
Thanks a lot!!
February 18, 2004 at 9:38 am
Identity columns can be one of decimal, int, numeric, smallint, bigint, or tinyint, a number by definition. They are normally assigned when a table is created, eg
CREATE TABLE [tablename] (rowid int IDENTITY(1,1), col1 char(1))
You do not specifiy the column when inserting, the system automatically generates it for you, eg
INSERT INTO [tablename] (col1) VALUES ('A')
If you want character based values then you will have to create them within a procedure prior to INSERT or use a trigger.
Far away is close at hand in the images of elsewhere.
Anon.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply