C#操作資料庫主外來鍵和級聯約束
a.Open();
SqlCommand conn1 = new SqlCommand("create database us on primary(name=us,filename='E:\\LT_home\\社群2.0\\us.mdf',size=5MB,maxsize=500MB)", a);
string sql2 = "use us create table test([賬號] int primary key not null,[密碼] varchar(15) not null,[姓名] varchar(20),[身份證] varchar(20),[聯絡方式] varchar(15))";
string sql3= "use us create table article(name varchar(30) not null,main text,time datetime default getdate(),number int )";
string sql4= "alter table article add constraint c1 foreign key (number) references test(賬號) on update cascade on delete cascade";
SqlCommand conn2 = new SqlCommand(sql2, a);
SqlCommand conn3 = new SqlCommand(sql3, a);
SqlCommand conn4 = new SqlCommand(sql4, a);
conn1.ExecuteNonQuery();
conn2.ExecuteNonQuery();
conn3.ExecuteNonQuery();
conn4.ExecuteNonQuery();
a.Close();
}