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
 General SQL Server Forums
 New to SQL Server Programming
 How to add identity to my existence column

Author  Topic 

Htwe Htwe
Starting Member

9 Posts

Posted - 2013-07-27 : 00:57:29
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

30421 Posts

Posted - 2013-07-27 : 02:15:23
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

52326 Posts

Posted - 2013-07-27 : 02:52:06
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 - 2013-07-27 : 03:06:52
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

30421 Posts

Posted - 2013-07-27 : 03:28:42
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 - 2013-07-27 : 03:44:39
Yes.

Thanks a lot

Thanks and Regards
Htwe Htwe
Go to Top of Page
   

- Advertisement -