Database Reference
In-Depth Information
mSqlConnection1.Close();
}
}
}
public void dropprimaryKey(string tableName,
string cnnString)
{
SqlDataReader mReader;
SqlConnection mSqlConnection = new
SqlConnection();
SqlCommand mSqlCommand = new SqlCommand();
string cnString = cnnString;
mSqlConnection = new SqlConnection(cnString);
mSqlConnection.Open();
//sp_pkeys is SQL Server default stored
procedure
//you pass it only table Name, it will return
//primary key column
mSqlCommand = new SqlCommand(“sp_pkeys”,
mSqlConnection);
mSqlCommand.CommandType = CommandType.
StoredProcedure;
mSq lCommand.Parameters.Add(“@table_name”,
SqlDbType.NVarChar).Value = tableName;
mReader = mSqlCommand.ExecuteReader();
while (mReader.Read())
{
try
{
SqlConnection mSqlConnection1 = new
SqlConnection(cnnString);
//the primary key column resides at
index 4
string str1 = “ALTER TABLE [“ +
tableName + “] DROP CONSTRAINT
[“ + mReader[5].ToString() + “]”;
mSqlConnection1.Open();
SqlCommand mSqlCommand1 = new
SqlCommand(str1, mSqlConnection1);
mSqlCommand1.ExecuteNonQuery();
mSqlConnection1.Close();
}
Search WWH ::




Custom Search