SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to add identity to my existence column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Htwe Htwe
Starting Member

9 Posts

Posted - 07/27/2013 :  00:57:29  Show Profile  Reply with Quote
Hello SqlTeam,

I have created a table and want to alter that table.
I want to add identity to my existence column.
How to add identity to my existence column?

Thanks in advance
Htwe Htwe

SwePeso
Patron Saint of Lost Yaks

Sweden
30277 Posts

Posted - 07/27/2013 :  02:15:23  Show Profile  Visit SwePeso's Homepage  Reply with Quote
ALTER TABLE dbo.Table1 ADD pkCol INT IDENTITY(1, 1) PRIMARY KEY
ALTER TABLE dbo.Table1 ADD pkCol INT IDENTITY(1, 1) PRIMARY KEY CLUSTERED



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 07/27/2013 :  02:52:06  Show Profile  Reply with Quote
you cant directly modify existing column to be of type identity. You need to do work around like this

http://www.mssqltips.com/sqlservertip/1397/add-or-drop-identity-property-for-an-existing-sql-server-column/

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Htwe Htwe
Starting Member

9 Posts

Posted - 07/27/2013 :  03:06:52  Show Profile  Reply with Quote
Hello,

I did ALTER TABLE statements.I got error like this--Column names in each table must be unique. Column name 'student_id' in table 'dbo.student' is specified more than once.
May I know about it.

Thanks in advance
Htwe Htwe
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30277 Posts

Posted - 07/27/2013 :  03:28:42  Show Profile  Visit SwePeso's Homepage  Reply with Quote
If you already have an unique column, you will have to go with visakhs suggestion.


Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

Htwe Htwe
Starting Member

9 Posts

Posted - 07/27/2013 :  03:44:39  Show Profile  Reply with Quote
Yes.

Thanks a lot

Thanks and Regards
Htwe Htwe
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000