I am using SQL server 2005 and when create a trigger I get the following error:
the code
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE TRIGGER dbo.dublicator
ON dbo.PLACE_ORDER
FOR INSERT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
INSERT INTO dbo.ADAPT_DR.DEBTS(CLIENT_CODE,CLIENT_NAME,CHARGES)
END
GO
When I execute I get the following error:
Msg 156, Level 15, State 1, Procedure dublicator, Line 17 Incorrect s开发者_开发问答yntax near the keyword 'END'.
I have tried solving it but nothing seems to work.
Since this is a trigger, I assume the values going into that second table will be from the insert. Answers stating use of VALUES
are valid SQL Syntax, but not what you're looking for. You will want to use the inserted
magic table.
INSERT INTO dbo.ADAPT_DR.DEBTS(CLIENT_CODE,CLIENT_NAME,CHARGES)
SELECT CLIENT_CODE, CLIENT_NAME, CHARGES
FROM inserted
This assumes the column names are the same in both tables. Please respond if you have any issues.
Your insert
statement is wrong - you're saying insert into the table debts
but not telling it what to insert. My suggestions is to read up and get some basic SQL knowledge (select, insert, update).
Your INSERT
statement is incomplete. It should be something like this:
INSERT INTO dbo.ADAPT_DR.DEBTS(CLIENT_CODE,CLIENT_NAME,CHARGES)
values (value1, value2, value3)
providing the values with in the corresponding data types of the columns specified.
精彩评论