Home > database >  SQL trigger an error, but I don't know where is the solution
SQL trigger an error, but I don't know where is the solution

Time:09-15

As shown in figure, there is a table and a trigger, near on the run times have grammar mistakes, don't know where is wrong, consult everybody

CodePudding user response:

Simple processing and grammar can be passed,
AS the back to pick the BEGIN

 USE tempdb for 
GO
The CREATE TABLE Truck (
VID varchar (15) constraint truck_pk primary KEY,
YEAR DATE,
Make a varchar (15),
VDesc varchar (30),
OdoReading varchar (10),
OdoReadingDate date,
PunchaseDate date,
Price varchar (15),
Assigned char (5),
EID varchar (15),
- the CONSTRAINT Truck_fk FOREIGN KEY (EID) REFERENCES ProEngineer (EID)
The CONSTRAINT assigned_cc CHECK ((assigned='Y') OR (assigned='N'))
);
GO
CREATE the TRIGGER check_Assigned
ON Truck AFTER the UPDATE AS
The BEGIN
IF the UPDATE (EID)
DECLARE @ old_EID varchar (15)
DECLARE @ new_EID varchar (15)
DECLARE @ old_assigned char (5)
DECLARE @ new_assigned char (5)
SELECT @ old_assigned=(SELECT assigned FROM does) SELECT @ new_assigned=(SELECT assigned FROM inserted) SELECT @ old_EID=(SELECT EID FROM does)
SELECT @ new_EID=(SELECT EID FROM inserted)
IF @ old_EID! And @ new_EID='No'!
='No'The BEGIN
PRINT 'This vehicle is assigned, do return vehicle! 'the ROLLBACK TRANSACTION
END
The ELSE
The BEGIN
PRINT 'Assign successfully'
END
The END;

CodePudding user response:

reference 1/f, gypsy song response:
simple processing and grammar can be passed,
AS the back to pick the BEGIN

 USE tempdb for 
GO
The CREATE TABLE Truck (
VID varchar (15) constraint truck_pk primary KEY,
YEAR DATE,
Make a varchar (15),
VDesc varchar (30),
OdoReading varchar (10),
OdoReadingDate date,
PunchaseDate date,
Price varchar (15),
Assigned char (5),
EID varchar (15),
- the CONSTRAINT Truck_fk FOREIGN KEY (EID) REFERENCES ProEngineer (EID)
The CONSTRAINT assigned_cc CHECK ((assigned='Y') OR (assigned='N'))
);
GO
CREATE the TRIGGER check_Assigned
ON Truck AFTER the UPDATE AS
The BEGIN
IF the UPDATE (EID)
DECLARE @ old_EID varchar (15)
DECLARE @ new_EID varchar (15)
DECLARE @ old_assigned char (5)
DECLARE @ new_assigned char (5)
SELECT @ old_assigned=(SELECT assigned FROM does) SELECT @ new_assigned=(SELECT assigned FROM inserted) SELECT @ old_EID=(SELECT EID FROM does)
SELECT @ new_EID=(SELECT EID FROM inserted)
IF @ old_EID! And @ new_EID='No'!
='No'The BEGIN
PRINT 'This vehicle is assigned, do return vehicle! 'the ROLLBACK TRANSACTION
END
The ELSE
The BEGIN
PRINT 'Assign successfully'
END
END;


I can't,,, near or ON the grammatical mistakes I don't know where is wrong,,,

CodePudding user response:

refer to the second floor weixin_47510094 response:
Quote: refer to 1st floor gypsy song response:

Simple processing and grammar can be passed,
AS the back to pick the BEGIN

 USE tempdb for 
GO
The CREATE TABLE Truck (
VID varchar (15) constraint truck_pk primary KEY,
YEAR DATE,
Make a varchar (15),
VDesc varchar (30),
OdoReading varchar (10),
OdoReadingDate date,
PunchaseDate date,
Price varchar (15),
Assigned char (5),
EID varchar (15),
- the CONSTRAINT Truck_fk FOREIGN KEY (EID) REFERENCES ProEngineer (EID)
The CONSTRAINT assigned_cc CHECK ((assigned='Y') OR (assigned='N'))
);
GO
CREATE the TRIGGER check_Assigned
ON Truck AFTER the UPDATE AS
The BEGIN
IF the UPDATE (EID)
DECLARE @ old_EID varchar (15)
DECLARE @ new_EID varchar (15)
DECLARE @ old_assigned char (5)
DECLARE @ new_assigned char (5)
SELECT @ old_assigned=(SELECT assigned FROM does) SELECT @ new_assigned=(SELECT assigned FROM inserted) SELECT @ old_EID=(SELECT EID FROM does)
SELECT @ new_EID=(SELECT EID FROM inserted)
IF @ old_EID! And @ new_EID='No'!
='No'The BEGIN
PRINT 'This vehicle is assigned, do return vehicle! 'the ROLLBACK TRANSACTION
END
The ELSE
The BEGIN
PRINT 'Assign successfully'
END
END;


I can't,,, near or ON the grammatical mistakes I don't know where is wrong,,,
 

USE tempdb for
GO
The CREATE TABLE Truck (
VID varchar (15) constraint truck_pk primary KEY,
YEAR DATE,
Make a varchar (15),
VDesc varchar (30),
OdoReading varchar (10),
OdoReadingDate date,
PunchaseDate date,
Price varchar (15),
Assigned char (5),
EID varchar (15),
- the CONSTRAINT Truck_fk FOREIGN KEY (EID) REFERENCES ProEngineer (EID)
The CONSTRAINT assigned_cc CHECK ((assigned='Y') OR (assigned='N'))
);
GO
CREATE the TRIGGER check_Assigned
ON Truck For UPDATE AS
The BEGIN
IF the UPDATE (EID)
DECLARE @ old_EID varchar (15)
DECLARE @ new_EID varchar (15)
DECLARE @ old_assigned char (5)
DECLARE @ new_assigned char (5)
nullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related