Re: Triggers



On Fri, 14 Mar 2008 08:39:53 -0700 (PDT), t8ntboy wrote:

I have never used triggers before and was wondering what the easiest
way to perform the following scenario would be:

I have a table called Courses and a table called Schedule. I would
like a corresponding record to be created automatcially in the
Schedule table when a record is added to the Course table.

What is the best and easiest way to do this?

Hi t8ntboy,

CREATE TRIGGER MyTrigger
ON dbo.Course AFTER INSERT
AS
IF @@ROWCOUNT = 0 RETURN;
SET NOCOUNT ON;

INSERT INTO Schedule (Col1, Col2, Col3, ...)
SELECT Col1, Col2, Col3, ...
FROM inserted;

go

Though you'd probably want to add some error handling.

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
.



Relevant Pages

  • Triggers
    ... I have never used triggers before and was wondering what the easiest ... way to perform the following scenario would be: ... I have a table called Courses and a table called Schedule. ...
    (comp.databases.ms-sqlserver)
  • Re: ldb file and Exclusive Access question
    ... Excel to report it. ... schedulable SQL server package. ... first db fro the 1st report I wanted to schedule. ... >database, the probability of database corruption is significantly increased. ...
    (comp.databases.ms-access)
  • Re: scheduling a t-sql stored procedures name in table column without creating a job for each on
    ... You want to schedule or simply run/put them on a Q and they run? ... Again I would still connect to SQL Server however it is that you want to do it, get all the possible procs from your Control table. ... I want to write a stored procedure that will ... You also do not need to use a Script task to do ...
    (microsoft.public.sqlserver.dts)
  • Re: How to design reporting?
    ... make sure the reports have the fields ... add fields for the selection criteria you want your users to use re: ... that is used to schedule and track completion of compliance courses for ...
    (microsoft.public.access.reports)
  • Re: How to design reporting?
    ... that is used to schedule and track completion of compliance courses for our ... I have completed forms for scheduling, editing scheduled courses, ... Report sorting is specified in the Sorting and Grouping ... under manager John. ...
    (microsoft.public.access.reports)