create trigger q0 on user
after insert,update,delete
as
begin
DECLARE @inserted int
declare @deleted int
select @inserted=COUNT(*) from inserted
select @deleted=COUNT(*) from deleted
if @inserted>0 and @deleted=0
begin
insert into friend(uId) select userId from inserted
end
else if @inserted>0 and @deleted>0
begin
DELETE FROM friend WHERE uId= (SELECT userId FROM DELETED)
insert into friend(uId) select userId from INSERTED
end
else if @inserted=0 and @deleted>0
begin
delete from friend
where uId=(select userId from deleted)
end
end
go
MYSQL运行一直说第一行报错
5 个解决方案
#1
第一个表格:
CREATE TABLE `user` (
`userId` CHAR(10) NOT NULL,
`userName` CHAR(10) NULL DEFAULT NULL,
`password` CHAR(10) NULL DEFAULT NULL,
`rPicture` VARCHAR(100) NULL DEFAULT NULL,
`rName` VARCHAR(10) NULL DEFAULT NULL,
`idNumeber` VARCHAR(18) NULL DEFAULT NULL,
`phone` VARCHAR(11) NULL DEFAULT NULL,
`sex` VARCHAR(2) NULL DEFAULT NULL,
`qq` VARCHAR(16) NULL DEFAULT NULL,
`picture` VARCHAR(100) NULL DEFAULT NULL,
`articleId` VARCHAR(10) NULL DEFAULT NULL,
`orderId` VARCHAR(10) NULL DEFAULT NULL,
`concernId` VARCHAR(10) NULL DEFAULT NULL,
PRIMARY KEY (`userId`),
INDEX `FK_user_order` (`orderId`),
INDEX `userId` (`userId`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
CREATE TABLE `user` (
`userId` CHAR(10) NOT NULL,
`userName` CHAR(10) NULL DEFAULT NULL,
`password` CHAR(10) NULL DEFAULT NULL,
`rPicture` VARCHAR(100) NULL DEFAULT NULL,
`rName` VARCHAR(10) NULL DEFAULT NULL,
`idNumeber` VARCHAR(18) NULL DEFAULT NULL,
`phone` VARCHAR(11) NULL DEFAULT NULL,
`sex` VARCHAR(2) NULL DEFAULT NULL,
`qq` VARCHAR(16) NULL DEFAULT NULL,
`picture` VARCHAR(100) NULL DEFAULT NULL,
`articleId` VARCHAR(10) NULL DEFAULT NULL,
`orderId` VARCHAR(10) NULL DEFAULT NULL,
`concernId` VARCHAR(10) NULL DEFAULT NULL,
PRIMARY KEY (`userId`),
INDEX `FK_user_order` (`orderId`),
INDEX `userId` (`userId`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
#2
CREATE TABLE `friend` (
`uId` CHAR(10) NOT NULL,
`getId` CHAR(10) NULL DEFAULT NULL,
`zid` VARCHAR(50) NULL DEFAULT NULL,
PRIMARY KEY (`uId`),
INDEX `uId` (`uId`)
)
`uId` CHAR(10) NOT NULL,
`getId` CHAR(10) NULL DEFAULT NULL,
`zid` VARCHAR(50) NULL DEFAULT NULL,
PRIMARY KEY (`uId`),
INDEX `uId` (`uId`)
)
#3
你是 MYSQL 的库吗 ? 明显这个 触发器是 MSSQL 的语法;
#4
楼主你这个是按照mssql语法写的触发器吧?不是mysql的
#5
那怎么改,请问
#1
第一个表格:
CREATE TABLE `user` (
`userId` CHAR(10) NOT NULL,
`userName` CHAR(10) NULL DEFAULT NULL,
`password` CHAR(10) NULL DEFAULT NULL,
`rPicture` VARCHAR(100) NULL DEFAULT NULL,
`rName` VARCHAR(10) NULL DEFAULT NULL,
`idNumeber` VARCHAR(18) NULL DEFAULT NULL,
`phone` VARCHAR(11) NULL DEFAULT NULL,
`sex` VARCHAR(2) NULL DEFAULT NULL,
`qq` VARCHAR(16) NULL DEFAULT NULL,
`picture` VARCHAR(100) NULL DEFAULT NULL,
`articleId` VARCHAR(10) NULL DEFAULT NULL,
`orderId` VARCHAR(10) NULL DEFAULT NULL,
`concernId` VARCHAR(10) NULL DEFAULT NULL,
PRIMARY KEY (`userId`),
INDEX `FK_user_order` (`orderId`),
INDEX `userId` (`userId`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
CREATE TABLE `user` (
`userId` CHAR(10) NOT NULL,
`userName` CHAR(10) NULL DEFAULT NULL,
`password` CHAR(10) NULL DEFAULT NULL,
`rPicture` VARCHAR(100) NULL DEFAULT NULL,
`rName` VARCHAR(10) NULL DEFAULT NULL,
`idNumeber` VARCHAR(18) NULL DEFAULT NULL,
`phone` VARCHAR(11) NULL DEFAULT NULL,
`sex` VARCHAR(2) NULL DEFAULT NULL,
`qq` VARCHAR(16) NULL DEFAULT NULL,
`picture` VARCHAR(100) NULL DEFAULT NULL,
`articleId` VARCHAR(10) NULL DEFAULT NULL,
`orderId` VARCHAR(10) NULL DEFAULT NULL,
`concernId` VARCHAR(10) NULL DEFAULT NULL,
PRIMARY KEY (`userId`),
INDEX `FK_user_order` (`orderId`),
INDEX `userId` (`userId`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
#2
CREATE TABLE `friend` (
`uId` CHAR(10) NOT NULL,
`getId` CHAR(10) NULL DEFAULT NULL,
`zid` VARCHAR(50) NULL DEFAULT NULL,
PRIMARY KEY (`uId`),
INDEX `uId` (`uId`)
)
`uId` CHAR(10) NOT NULL,
`getId` CHAR(10) NULL DEFAULT NULL,
`zid` VARCHAR(50) NULL DEFAULT NULL,
PRIMARY KEY (`uId`),
INDEX `uId` (`uId`)
)
#3
你是 MYSQL 的库吗 ? 明显这个 触发器是 MSSQL 的语法;
#4
楼主你这个是按照mssql语法写的触发器吧?不是mysql的
#5
那怎么改,请问