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 |
|
wangyc77
Yak Posting Veteran
65 Posts |
Posted - 2007-01-31 : 00:35:18
|
| I used [select into] statement to create a table, but the table has no primary key.How do I create a primary key for that existing table using SQL and the primary key(called Sno field) should be increamental.Thank youJon |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-01-31 : 00:45:35
|
[code]ALTER TABLE dbo.tbl ADD CONSTRAINTPK_tbl PRIMARY KEY ( pk_col)[/code]is Sno an existing column ? KH |
 |
|
|
wangyc77
Yak Posting Veteran
65 Posts |
Posted - 2007-01-31 : 00:46:16
|
| nope |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-01-31 : 00:50:31
|
[code]alter table dbo.tbl add Sno int not null identity(1,1)ALTER TABLE dbo.tbl ADD CONSTRAINTPK_tbl PRIMARY KEY ( Sno)[/code] KH |
 |
|
|
wangyc77
Yak Posting Veteran
65 Posts |
Posted - 2007-01-31 : 00:56:54
|
| Thanks a lot, save me lots of time**Jonathan** |
 |
|
|
wangyc77
Yak Posting Veteran
65 Posts |
Posted - 2007-01-31 : 01:03:35
|
| Just curious, what does that identity(1,1) mean?**Jonathan** |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-01-31 : 01:06:36
|
from BOLquote: IDENTITY (Property)Creates an identity column in a table. This property is used with the CREATE TABLE and ALTER TABLE Transact-SQL statements.Note The IDENTITY property is not the same as the SQL-DMO Identity property that exposes the row identity property of a column. SyntaxIDENTITY [ ( seed , increment ) ]
KH |
 |
|
|
|
|
|