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

Alter table 1

Status
Not open for further replies.
Oct 17, 2006
227
what is the syntax for adding a uid on a table eg


ALTER TABLE #test
ADD uid int

this puts nulls but against uid but I want to seed it so uid code1
1 A
2 B
3 C


Thanks
 
If I understood you correctly you want to add an identity fields to temporary table.
Code:
ALTER TABLE #test ADD uid int IDENTITY(1,1)

But I have one question, why you didn't add this column when you create the table?


Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Spot on!! does it make any difference

if ADD uid int IDENTITY Primary Key ??

Ps there is no PK set.
 
PK in temporary table? why?
Because I don't know what you are trying to do, what is your data, but sure you could do that:
Code:
alter table #test ADD uid int IDENTITY(1,1) PRIMARY KEY

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Boris,

Primary keys on temp tables can improve performance, especially with complicated joins on the temp table. This is something I do all the time. You can even put a primary key on a table variable.

Ex.

[tt][blue]
Declare @Temp
Table (RowId Integer Identity(1,1) Primary Key Clustered,
Field1 Int,
Field2 VarChar(20)
)
[/blue][/tt]



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top