1
我有一個查詢刪除級聯,在這裏查詢創建的更新和刪除級聯
create table satuan_type
(
id int identity(1,1),
satuan_id int(200),
type_id int,
primary key(id),
foreign key(satuan_id) references satuan(id) on update cascade on delete cascade
);
的問題是,如何創建/添加,刪除和用C#級聯更新?所以查詢是運行/克里特自動在這種方法
Dictionary<String, String> dic = new Dictionary<string, string>();
dic.Add("id", "INT PRIMARY KEY IDENTITY");
dic.Add("satuan_id", "INT");
dic.Add("type_id", "INT");
cDatabaseSQLServer.CreateTables("satuan_type", dic);
public int CreateTables(String tableName, Dictionary<String, String> data)
{
switch (sqlType)
{
case DATABASE_SQL_TYPE.DATABASE_SQL_TYPE_SQLITE:
return cSQLite.CreateTables(tableName, data);
case DATABASE_SQL_TYPE.DATABASE_SQL_TYPE_MSSQL:
return cSQL.CreateTables(tableName, data);
}
return 0;
}
public int CreateTables(String tableName, Dictionary<String, String> data)
{
string s = "CREATE TABLE " + tableName + " (";
bool first = true;
foreach (KeyValuePair<String, String> val in data)
{
if (first)
{
first = false;
}
else
{
s = s + ",";
}
string s1;
s1 = String.Format("{0} {1}", val.Key, val.Value);
s = s + s1;
}
s = s + ")";
return this.ExecuteNonQuery(s);
}
刪除級聯往往不是一個壞主意。 –
如果你要這麼長,使用ORM。做事更容易,更好。 – MSI