我有一个删除级联的查询,这里是查询
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);
}