I am student of RDBMS.
I have very basic question let say I have one existing Table in SQL server. What will be script to alter table.
- Drop Column ‘RowId’ if exist.
- Drop contraint if exist.
- Add one new column ‘RowId’ into table.
- Make this column as primary key.
- Autoincrement type int.
In SQL Server 2005 or newer, you could use this script:
Of course, this script may still fail, if other tables are referencing this
dbo.YourTableusing foreign key constraints onto the pre-existingRowIdcolumn…Update: and of course, anywhere I use
dbo.YourTableorPK_YourTable, you have to replace those placeholder with the actual table / constraint names from your own database (you didn’t mention what they were, in your question…..)