Change SQL Server primary key using C# -
i need change column type in sql server table.
i need using script or c#.
the original datatype integer
, new type varchar(50)
.
i can using sql script:
alter table confezionamento alter column partnumber varchar(50)
but problem column in set of primary keys.
when try execute, error occurred because pk_confezionamento
using column.
how can without access sql server management studio?
you need run sql commands following steps:
- drop primary key constraint
- alter primary key
- add primary key constraint
if there foreign keys or indexes, may have deal them well.
the commands looking similar these:
alter table confezionamento drop constraint pk_confezionamento alter table confezionamento alter column partnumber varchar(50) alter table confezionamento add constraint pk_confezionamento primary key (partnumber)
these commands can sent c# using ado.net or similar methods.
Comments
Post a Comment