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 ,[Name] varchar(10) unique)
insert Ta select 1,'A'
insert Ta select 2,'B'
insert Ta select 3,null
create table tb(ID int ,[test] varchar(10) foreign key references ta([name]) on update cascade)
insert tb select 1,null
go
if object_id('ta')is not null drop table ta
go
create table ta(Id int ,[Name] varchar(10) unique)
insert Ta select 1,'A'
insert Ta select 2,'B'
insert Ta select 3,null
create table tb(ID int ,[test] varchar(10) foreign key references ta([name]) on update cascade)
insert tb select 1,null
go
if object_id('ta')is not null drop table ta
go
create table ta(Id int ,[Name] varchar(10) unique)
insert Ta select 1,'A'
insert Ta select 2,'B'
insert Ta select 3,null
insert ta select 4,''
create table tb(ID int ,[test] varchar(10) foreign key references ta([name]) on update cascade)
insert tb select 1,null
insert tb select 2,''
select * from tb
/*
ID test
----------- ----------
1 NULL
2 (影響 2 個資料列)*/
go
if object_id('ta')is not null drop table ta
go
create table ta(Id int ,[Name] varchar(10) unique)
insert Ta select 1,'A'
insert Ta select 2,'B'create table tb(ID int ,[test] varchar(10) foreign key references ta([name]) )
insert tb select 1,null
select * from tb
/*
ID test
----------- ----------
1 NULL(1 行受影响)
*/