modify columns of an existing table

  • hey every one

    i m trying to write a c# program that creates and edits sql tables. i couldn't find any t-sql (or smo) command that removes primary key / identity from an existing column.

    (like changing the primary key or identity)

    i have already thought about alter table - deleting the existing constraint and creating a new one, but it didnt work -

    this might be rarely used but still needed.

    any ideas?

  • You'll have to drop all foreign key constraints against the table first by using

    ALTER TABLE OtherTableName DROP CONSTRAINT ConstraintName against all the related tables. Then you can use ALTER TABLE TableName DROP CONSTRAINT pkNameto remove the primary key.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • sorry i have been away for a while.

    thanks for your reply, but my table doesn't have any foreign key constraints, so i just drop the pk constraints...

    thanks again

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply