insert no. automatically  
Author Message
ConfusedStudent





PostPosted: Thu Apr 27 00:02:32 CDT 2006 Top

SQL Server Developer >> insert no. automatically

Hi,

I have a table with 400-500 records, I want to insert srno (1,2,3....) to
each record, How can I ?


HSS

SQL Server187  
 
 
Roji





PostPosted: Thu Apr 27 00:02:32 CDT 2006 Top

SQL Server Developer >> insert no. automatically If the order actually doesn't matters then




UPDATE YourTable




--
Regards
Roji. P. Thomas
http://toponewithties.blogspot.com


> Hi,
>
> I have a table with 400-500 records, I want to insert srno (1,2,3....) to
> each record, How can I ?
>
>
> HSS
>
>
>
>
>


 
 
Zero





PostPosted: Thu Apr 27 00:35:49 CDT 2006 Top

SQL Server Developer >> insert no. automatically Hi,

You can add one more column with IDENTITY to your table.

Here is an example how it works:

CREATE TABLE t6(xx int default 20, yy int)
INSERT into t6 DEFAULT VALUES
INSERT into t6 DEFAULT VALUES
INSERT into t6 DEFAULT VALUES
INSERT into t6 DEFAULT VALUES

SELECT * FROM t6

alter TABLE t6 add id int IDENTITY

SELECT * FROM t6
DROP TABLE t6

Hope this helps.
Cheers!
Manish

 
 
Uri





PostPosted: Thu Apr 27 00:51:00 CDT 2006 Top

SQL Server Developer >> insert no. automatically Hi
Pehaps you need to add an IDENTITY property to the table

CREATE TABLE #Test (c1 INT NOT NULL)

INSERT INTO #Test VALUES (100)
INSERT INTO #Test VALUES (200)


ALTER TABLE #Test ADD c2 INT IDENTITY(1,1)
GO
SELECT * FROM #Test



> Hi,
>
> I have a table with 400-500 records, I want to insert srno (1,2,3....) to
> each record, How can I ?
>
>
> HSS
>
>
>
>
>