Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql server set complex constraints

CREATE FUNCTION dbo.fnIsAddressOwner (
  @CustomerId int,
  @AddressId int
)
RETURNS tinyint
AS
BEGIN
  DECLARE @Result tinyint
  IF EXISTS(SELECT * FROM CustomerAddresses WHERE CustomerId=@CustomerId and AddressId=@AddressId)
    SET @Result= 1
  ELSE 
    SET @Result= 0
  RETURN @Result
END


CREATE TABLE Customers (
  CustomerId int,
  PreferredAddressId int,
  CONSTRAINT ckPreferredAddressId CHECK (
    dbo.fnIsAddressOwner(CustomerId, PreferredAddressId) = 1)
  )
)
Comment

PREVIOUS NEXT
Code Example
Sql :: oracle privileges 
Sql :: SQL Modulo (Remainder) Operator 
Sql :: sql int vs integer 
Sql :: sql server manager close connection 
Sql :: load utilities in sql server 
Sql :: sql truncate table referencing itself 
Sql :: edad en oracle 
Sql :: sql shell psql cannot enter password 
Sql :: sql mod even odd 
Sql :: storing RGBA in mysql db 
Sql :: from UCSC MySQL database Use database hg38. 
Sql :: spfile oracle 
Sql :: suse stop MySQL 
Sql :: narural join 
Sql :: ring MySQL create new table and insert records 
Sql :: how to convert exponential expression to n decimal float in postgresql 
Sql :: psql limit order group by 
Sql :: pl sql join 3 tables 
Sql :: mysql select where field like in list 
Sql :: postgres row expiration 
Sql :: oracle generate sequence of numbers 
Sql :: oracle database table to check invalid login attempts 
Sql :: sql server query field names 
Sql :: select into a new table mysql 
Sql :: conectar base de datos mysql con java 
Sql :: copy row from db to db mysql 
Sql :: postgresql custom order by 
Sql :: fonction stockée pl/sql 
Sql :: extract domain name from email id mariadb 
Sql :: sql server agent not running 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =