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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Sorry...beginner question re: insert statement

Author  Topic 

Dmagnus
Starting Member

1 Post

Posted - 2010-04-06 : 23:01:41
I have a table with three columns: Fname, Lname, Email_Address. I need to insert a column to serve as an ID or Primary Key...just a simple numeric value, perhaps starting at 1 and going the length of the table.

Can you describe how to do this?

Thanks.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-04-06 : 23:07:05
add an identity column to the table

ALTER TABLE <table name> ADD <column name> INTEGER IDENTITY



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-07 : 00:21:08
and to add to that you can specify a custom seed value and increment also if you need ID value to start from it like 1000

ALTER TABLE <table name> ADD <column name> INTEGER IDENTITY(1000,1)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Asken
Starting Member

38 Posts

Posted - 2010-04-07 : 04:13:55
If you're a beginner you can use the SQL Server Enterprise Manager, if you have it, to do all your changes graphically which would probably help you get started.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-04-07 : 04:43:06
"SQL Server Enterprise Manager"

"SQL Server Management Server Studio" (a.k.a. "SSMS") in SQL 2008
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-07 : 04:55:59
quote:
Originally posted by Kristen

"SQL Server Enterprise Manager"

"SQL Server Management Server" (a.k.a. "SSMS") in SQL 2008


SQL Server Management Studio


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Asken
Starting Member

38 Posts

Posted - 2010-04-07 : 05:05:56
Sorry about that :)

Reporting & Analysis Specialist
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-04-07 : 05:18:00
Hahaha ... you and me both!!
Go to Top of Page
   

- Advertisement -