А
Size: a a a
А
DN
А
А
CREATE TABLE foo (
bar int NOT NULL,
fred Int NOT NULL
)
GO
create or alter Function dbo.myCheckFunc(
@val1 int, @val2 int
)
returns int
as
Begin
if exists (select 1 from foo where (bar = @val1 and fred = @val2) or (bar = @val2 and fred = @val1))
return 0
return 1
end
GO
alter table foo drop constraint CK_constraintName
truncate table foo
alter table foo with check add constraint CK_constraintName
CHECK (dbo.myCheckFunc(bar,fred)>0)
select [dbo].[myCheckFunc](1,2) --returns 1
select * from foo --0 rows
insert into foo (bar,fred)
values (1,2)--throw constraint error
А
CREATE TABLE foo (
bar int NOT NULL,
fred Int NOT NULL
)
GO
create or alter Function dbo.myCheckFunc(
@val1 int, @val2 int
)
returns int
as
Begin
if exists (select 1 from foo where (bar = @val1 and fred = @val2) or (bar = @val2 and fred = @val1))
return 0
return 1
end
GO
alter table foo drop constraint CK_constraintName
truncate table foo
alter table foo with check add constraint CK_constraintName
CHECK (dbo.myCheckFunc(bar,fred)>0)
select [dbo].[myCheckFunc](1,2) --returns 1
select * from foo --0 rows
insert into foo (bar,fred)
values (1,2)--throw constraint error
А
А
4
А
А
1,2left join ->
1,3
1,2 1,2
1,3 1,2
1,2 1,3
1,3 1,3
IZ
4
1,2left join ->
1,3
1,2 1,2
1,3 1,2
1,2 1,3
1,3 1,3
ДЗ
IZ
M
IZ
I
M
M
O