Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 24th, 2004, 04:17 AM
Registered User
 
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Update a table with the sql string

Hi...

I have a table named Employee (with columns ID, Name, Surname) and another table named Employee_UPDATE (with columns ID, Sql_String).

I need a trigger(s). If I make an insert, update or delete on Employee, trigger should add the Sql string of the command into the Employee_Update table.

For example,
If a insert an item in Employee like ;
       500, Bill, Nash

Trigger must add the below string to the Employee_UPDATE

INSERT INTO Employee_UPDATE (Sql_String)
                 VALUES ('INSERT INTO Employee (ID. Name. Surname)
                             VALUES (500, Bill. John)'
                         )

I want to make such a things.
How can I do that?

Thanks for help...
 
Old April 24th, 2004, 08:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

I dont think you need an Id Column there in your Employee_UPDATE table. Anyways It is your call.

I dont think it would be possible to write it that way, as you say you wanted to store the SQL statement used for INSERT/UPDATE/DELETE operation. Coz, how can the trigger know what statement(DML) you used lastly, also unlike Stored Procedures/Functions the Triggers never take Parameters.

May be if you are tryin g to do this from your client application(Front end), this is possible.
Any time you run a DML(Data Manipulation Language) statement, you can format that string and simultaneously run the Insert on EMPLOYEE_UPDATE table with the Query you generated to Insert on EMPLOYEE table.

Anyone, correct me if I am wrong.

Cheers!

-Vijay G
 
Old April 25th, 2004, 11:09 PM
Authorized User
 
Join Date: Jun 2003
Posts: 77
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Check this out:

http://vyaskn.tripod.com/tracking_sq...y_triggers.htm
 
Old April 26th, 2004, 05:19 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Defiant,

That was great to know. You made me know that this is still possible. I learnt something new at the moment.

Thanks,


-Vijay G





Similar Threads
Thread Thread Starter Forum Replies Last Post
Update one table to another table using DTS in SQL Printmaker SQL Language 0 July 24th, 2007 07:17 AM
Update table using SQL query from form pater53 Access VBA 4 January 24th, 2007 11:24 AM
How can I update 2 rows in one column in SQL table babou Classic ASP Databases 6 March 9th, 2005 11:13 AM
Update SQL table with data from FoxPro system sofya SQL Server 2000 6 November 4th, 2004 06:45 PM
update table (SQL & DataSet) melvik ADO.NET 1 July 24th, 2003 04:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.