开发一个触发器,该触发器将放置在营销列表表中,一旦尝试插入,该触发器将在此人的年龄小于 18 岁时将一条记录插入到子表中。
请参阅下面的代码:
Create Trigger on_insert_marketing_list
On marketing_list for insert
As
BEGIN
Declare @Name varchar (100)
Declare @Dob date
Declare @Gender char(1)
Declare @Parish VARCHAR(50)
Declare @Mobile varchar(50)
Declare @Provider varchar(50)
Declare @age int
Select @age = datediff(year,@dob,getdate())from inserted
If (@age) < 18
BEGIN
Insert Into Childlist values(@Name,@Dob,@Gender,@Parish,@Mobile,@Provider)
END
End
insert into marketing_list (Name, Dob, Gender, Parish, Mobile, Mobile_Provider) values
('Kendrick Lamar', '3/4/2005','M','Kingston', '18764532345','LIME')