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 |
|
ccbryan
Starting Member
4 Posts |
Posted - 2010-02-23 : 09:21:05
|
| Hi, quick question here... I am uploading data from retail outlets to the corporate office, and I want to ensure that credit card data is not recorded at corporate. I'm thinking an INSERT trigger like this one would be a good way to handle this:CREATE TRIGGER [TRIGGER NAME] ON [dbo].[payments] FOR INSERTASupdate dbo.payments set cardnumber = '', cardname = '', carexpire = '' However, I want to make sure the update statement applies only to the record being inserted. Will that be true the way this trigger is written? If not, how should it look?Thanks,Chandler |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-23 : 09:24:37
|
for that you need to do join with insertedCREATE TRIGGER [TRIGGER NAME] ON [dbo].[payments] FOR INSERTASupdate p set p.cardnumber = '', p.cardname = '', p.carexpire = '' from dbo.payments pjoin inserted ion i.pk=p.pk pk is primary key of tableb/w dont you need to have trigger for update as well? just in case, somebody changes an already existing value of table in [dbo].[payments]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
ccbryan
Starting Member
4 Posts |
Posted - 2010-02-23 : 10:14:48
|
| Sweet! Thank you Visakh. And thanks for the UPDATE suggestion... |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-23 : 10:18:41
|
welcome ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-02-23 : 10:29:55
|
Couple of suggestions:Assuming you are bulk uploading the data to corporate then the Trigger will create additional log entries (could be significant if volumes are large).You might want to have the Bulk Upload set these fields to blank, and then have the trigger conditionally update only if any of these columns are NOT blank - that way it won't re-update rows that don't need it |
 |
|
|
|
|
|