create table tb1 ( id1 int identity(1,1), val1 varchar(10) ) create table tb2 ( id1 int, val2 varchar(10) )alter table tb1 add constraint pk_tb1 primary key(id1);alter table tb2 alter column id1 int not null; alter table tb2 add constraint pk_tb2 primary key(id1);alter table tb2 add constraint fk_tb2 foreign key(id1) references tb1(id1) ON UPDATE CASCADE ; 是可以的,但是为什么要这么做呢?一般都是组合主键才会创建外键 这样这两个表好像没有必要啊,除非只是为了备份需要
--TRY 就知道了if object_id('tb')is not null drop table tb go if object_id('ta')is not null drop table ta go create table ta(ID int identity primary key ,[name] varchar(10)) go create table tb(id int primary key foreign key references ta(ID) on update cascade,[test] varchar(10))
create table tb1
(
id1 int identity(1,1),
val1 varchar(10)
)
create table tb2
(
id1 int,
val2 varchar(10)
)alter table tb1 add constraint pk_tb1 primary key(id1);alter table tb2 alter column id1 int not null;
alter table tb2 add constraint pk_tb2 primary key(id1);alter table tb2 add constraint fk_tb2 foreign key(id1) references tb1(id1) ON UPDATE CASCADE ;
是可以的,但是为什么要这么做呢?一般都是组合主键才会创建外键
这样这两个表好像没有必要啊,除非只是为了备份需要
go
if object_id('ta')is not null drop table ta
go
create table ta(ID int identity primary key ,[name] varchar(10))
go
create table tb(id int primary key foreign key references ta(ID) on update cascade,[test] varchar(10))
node表:nodeID,fk,自增
store表:storeID,fk,pk(refrence node(nodeID))我想知道这样在Store进行插入删除等数据库操作的时候是不是可行,因为有人说不行,却没说为什么,我很疑惑,想请各位高手能帮我解释一下
node表:nodeID,pk,自增
store表:storeID,pk,fk(refrence node(nodeID))
on cascade update