i trying delete all primary keys one table on SQL. If i had one primary key, i can deleted this code line:
ALTER TABLE dbo.TblName DROP CONSTRAINT PK_TblName;
But, if i have one more primary keys, i take this error:
Msg 3728, Level 16, State 1, Line 18 'PK_TblBooks' is not a constraint. Msg 3727, Level 16, State 0, Line 18 Could not drop constraint. See previous errors.
And i try this on C# but they arent deleted:
String sql= "SELECT COL_NAME(ic.object_id,ic.column_id) AS ColumnName FROM sys.indexes AS i INNER JOIN sys.index_columns AS ic ON i.object_id = ic.object_id WHERE i.is_primary_key = 1 AND ic.object_id = i.object_id";
SqlCommand cmd= new SqlCommand(sql, con);
SqlDataAdapter adp= new SqlDataAdapter(cmd);
DataTable dtsk = new DataTable();
adp.Fill(dtsk);
for (int i = 0; i < dtsk.Rows.Count; i++)
{
String remove= "ALTER TABLE " + Table + " DROP CONSTRAINT PK_" + Table + "";
SqlCommand cmd1= new SqlCommand(remove, con);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
}
How can watchin way for solve this problem?