| Author |
Topic |
|
Jeskit@hotmail.co.uk
Starting Member
20 Posts |
Posted - 2007-12-18 : 12:01:27
|
| hii've been asked to write a sql sequence for a database i'm building but i haven't been using SQL very long and i have no idea how to write a sequence. Does anyone know anything about sql sequences?thanksjessica |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-12-18 : 12:05:00
|
| Explain what you mean by "sql sequence" perhaps with some sample data?Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
Jeskit@hotmail.co.uk
Starting Member
20 Posts |
Posted - 2007-12-18 : 12:18:24
|
| hisorry i meant triggerssorryjessica |
 |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-12-18 : 12:19:54
|
| Please explain the entire task that you are working on and the issue you are facing. I have no idea what you are asking..Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2007-12-18 : 12:22:31
|
| Create Trigger {Your_Trigger} ON {Your_Table}FOR/INSTEAD OF(when u want trigger to fire ) INSERT/UPDATE/DELETE (for what all actions you need to trigger the code below)AS.........code here.......GO |
 |
|
|
Jeskit@hotmail.co.uk
Starting Member
20 Posts |
Posted - 2007-12-18 : 12:25:07
|
| hisorry, i have to implement a trigger which will audit the table to automatically log all changes made to data in two certain tables. the trigger needs to log new and old vbvalues of the data.thanksjessica |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2007-12-18 : 12:32:20
|
something like this. :-CREATE TRIGGER TABLE_AUDIT ON {Table_Name}FOR INSERT,UPDATE,DELETEASIF EXISTS(SELECT * FROM INSERTED)BEGININSERT INTO New_ValuesSELECT {fields} FROM INSERTEDENDIF EXISTS(SELECT * FROM DELETED)BEGININSERT INTO Old_ValuesSELECT {fields} FROM DELETEDENDGO |
 |
|
|
Jeskit@hotmail.co.uk
Starting Member
20 Posts |
Posted - 2007-12-18 : 12:41:40
|
| hitried that it saying i'm missing BEFORE, AFTER or INSTEAD OF keywordCREATE TRIGGER TABLE_AUDIT ON {Difficulty_ratings}FOR INSERT,UPDATE,DELETEASIF EXISTS(SELECT * FROM INSERTED)BEGININSERT INTO Difficulty_ratingsSELECT {Hoilday_code, Description_of_ratings} FROM INSERTEDENDIF EXISTS(SELECT * FROM DELETED)BEGININSERT INTO Difficulty_ratingsSELECT {Hoilday_code, Description_of_ratings} FROM DELETEDENDGO |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2007-12-18 : 12:51:33
|
| [code]CREATE TRIGGER TABLE_AUDIT ON {Table_Name}AFTER INSERT,UPDATE,DELETEASBEGINIF EXISTS(SELECT * FROM INSERTED)BEGININSERT INTO New_ValuesSELECT {fields} FROM INSERTEDENDIF EXISTS(SELECT * FROM DELETED)BEGININSERT INTO Old_ValuesSELECT {fields} FROM DELETEDENDENDGO[/code] |
 |
|
|
Jeskit@hotmail.co.uk
Starting Member
20 Posts |
Posted - 2007-12-18 : 12:57:00
|
| nope still not working still saying missing BEFORE, AFTER or INSTEAD OF keywordCREATE TRIGGER TABLE_AUDIT ON {Difficulty_ratings}AFTER INSERT,UPDATE,DELETEASIF EXISTS(SELECT * FROM INSERTED)BEGININSERT INTO Difficulty_ratingsSELECT {Hoilday_code, Description_of_ratings} FROM INSERTEDENDIF EXISTS(SELECT * FROM DELETED)BEGININSERT INTO Difficulty_ratingsSELECT {Hoilday_code, Description_of_ratings} FROM DELETEDENDGO |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2007-12-18 : 13:07:11
|
quote: Originally posted by Jeskit@hotmail.co.uk nope still not working still saying missing BEFORE, AFTER or INSTEAD OF keywordCREATE TRIGGER TABLE_AUDIT ON {Difficulty_ratings}AFTER INSERT,UPDATE,DELETEASIF EXISTS(SELECT * FROM INSERTED)BEGININSERT INTO Difficulty_ratingsSELECT {Hoilday_code, Description_of_ratings} FROM INSERTEDENDIF EXISTS(SELECT * FROM DELETED)BEGININSERT INTO Difficulty_ratingsSELECT {Hoilday_code, Description_of_ratings} FROM DELETEDENDGO
CREATE TRIGGER TABLE_AUDIT ON Difficulty_ratingsAFTER INSERT,UPDATE,DELETEASIF EXISTS(SELECT * FROM INSERTED)BEGININSERT INTO Difficulty_ratingsSELECT Hoilday_code, Description_of_ratings FROM INSERTEDENDIF EXISTS(SELECT * FROM DELETED)BEGININSERT INTO Difficulty_ratingsSELECT Hoilday_code, Description_of_ratings FROM DELETEDENDGO |
 |
|
|
Jeskit@hotmail.co.uk
Starting Member
20 Posts |
Posted - 2007-12-18 : 13:10:53
|
| nope still saying that i'm missing BEFORE, AFTER or INSTEAD OF keyword |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2007-12-18 : 13:16:08
|
| try putting BEGIN END after CREATE?refer this too[url]http://msdn2.microsoft.com/en-us/library/ms189799.aspx[/url] |
 |
|
|
Jeskit@hotmail.co.uk
Starting Member
20 Posts |
Posted - 2007-12-18 : 13:44:41
|
| HIIts still not working, its still saying i'm missing BEFORE, AFTER or INSTEAD OF keywordCREATE TRIGGER TABLE_AUDIT ON Difficulty_ratingsBEGINAFTER INSERT,UPDATE,DELETEASIF EXISTS(SELECT * FROM INSERTED)INSERT INTO Difficulty_ratingsSELECT Hoilday_code, Description_of_ratings FROM INSERTEDENDBEGINIF EXISTS(SELECT * FROM DELETED)INSERT INTO Difficulty_ratingsSELECT Hoilday_code, Description_of_ratings FROM DELETEDENDGO |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-12-18 : 14:07:16
|
Read the excellent SQL Server help file Books Online for syntax help. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|