如何取消外键关系?
比如说表stu和tea,创建时是这样createtabletea(t_namevarchar(10)notnullprimarykey);createtablestu(s...
比如说表stu和tea,创建时是这样
create table tea(
t_name varchar(10) not null primary key
);
create table stu(
s_name varchar(10) not null primary key,
s_myteacher(10) not null,
constraint pk_myteacher foreign key(s_myteacher) references tea(t_name)
);
要删除s_myteacher和表tea中t_name的外键关系,SQL语句应该怎么写?
如果我在设置的时候constraint pk_myteacher这项没写,那默认的约束关系是什么呢? 展开
create table tea(
t_name varchar(10) not null primary key
);
create table stu(
s_name varchar(10) not null primary key,
s_myteacher(10) not null,
constraint pk_myteacher foreign key(s_myteacher) references tea(t_name)
);
要删除s_myteacher和表tea中t_name的外键关系,SQL语句应该怎么写?
如果我在设置的时候constraint pk_myteacher这项没写,那默认的约束关系是什么呢? 展开
展开全部
SQLSQRVER:
alter table stu drop constraint pk_myteacher
如果我在设置的时候constraint pk_myteacher这项没写,那默认的约束关系是什么呢
------------------------
可以这样查:
select t2.name from sysforeignkeys t1,sysobjects t2
where t1.constid=t2.id and t2.xtype='F' and t2.parent_obj=object_id('stu')
and t1.fkeyid=object_id('stu') and rkeyid=object_id('tea')
alter table stu drop constraint pk_myteacher
如果我在设置的时候constraint pk_myteacher这项没写,那默认的约束关系是什么呢
------------------------
可以这样查:
select t2.name from sysforeignkeys t1,sysobjects t2
where t1.constid=t2.id and t2.xtype='F' and t2.parent_obj=object_id('stu')
and t1.fkeyid=object_id('stu') and rkeyid=object_id('tea')
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询