Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
meishern
Starting Member
1 Post |
Posted - 2006-08-16 : 13:36:55
|
| Hi.Please help me.Table 'Counter' has a date field and an integer field. I want to auto increase the integer field by 1 using the update statement. I DO NOT want to first run a select statement to find out the initial value of the integer field prior to incrementing it. how would i go about doing this?Thanks a lot! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-08-16 : 14:12:14
|
| Just use the IDENTITY option for this. It allows SQL Server to manage the column for you. Check out the below example. Notice how I don't insert any data into Column1, yet I get a value for it.CREATE TABLE Table1(Column1 int IDENTITY(1, 1), Column2 varchar(50))INSERT INTO Table1 (Column2) VALUES ('Tara')INSERT INTO Table1 (Column2) VALUES ('Mike')SELECT * FROM Table1DROP TABLE Table1Tara Kizer |
 |
|
|
|
|
|