Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
askmanojjain
Starting Member
10 Posts |
Posted - 2007-07-26 : 13:48:03
|
I have converted Access database to sql express. Access Database had AutoNumber FIelds for which trigger was generated by Upsizing wizard.Now when I import data from client the autonumber field value changes because trigger is fired which distroys all linksI want to modify trigger so that it generates new number only when it is not supplied in a insert command.Please help. Code is given below. Also suggest how to save because when I use save, it asks for a new .sql file name and a new file is generated instead of modifying the same triggerset ANSI_NULLS ONset QUOTED_IDENTIFIER ONGOALTER TRIGGER [dbo].[T_AcControlLimit_ITrig] ON [dbo].[AcControlLimit] FOR INSERT ASSET NOCOUNT ONDECLARE @randc int, @newc int /* FOR AUTONUMBER-EMULATION CODE *//* * RANDOM AUTONUMBER EMULATION CODE FOR FIELD 'IntAcControlCode' */SELECT @randc = (SELECT convert(int, rand() * power(2, 30)))SELECT @newc = (SELECT IntAcControlCode FROM inserted) UPDATE AcControlLimit SET IntAcControlCode = @randc WHERE IntAcControlCode = @newc |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-07-26 : 13:52:30
|
You need an update trigger and not an insert trigger.You don't save these, you execute them. Click F5 or hit the green arrow to execute the code. It then puts it into the database.Tara Kizerhttp://weblogs.sqlteam.com/tarad/ |
|
|
askmanojjain
Starting Member
10 Posts |
Posted - 2007-07-31 : 14:29:45
|
THANKS TKIZERI wuld like to share one good solution I have got. MS has released a "DataBase Publishing wizard" and it can do what I want.i.e. transer data from a sql databaseto other or simple create "Views" in any database etc.I am trying this solution and hope fully it will work fine. |
|
|
|
|
|