Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Update Trigger
Message
From
25/02/2016 14:14:34
John Baird
Coatesville, Pennsylvania, United States
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Title:
Environment versions
SQL Server:
SQL Server 2008 R2
OS:
Windows 7
Network:
Windows 2008 Server
Miscellaneous
Thread ID:
01632080
Message ID:
01632082
Views:
48
>>I have a requirement to define 2 columns in ddl as NOT NULL one gets a default constraint but the other can't be added until it is set to a value from the same record.
>>
>>So I have
>>UpdateBy nvarchar(128) NULL
>>UpdateTime datetime NOT NULL
>>
>>I then update UpdateBy setting it equal to CreateBy and then altering the column and setting it not null.
>>
>>This works just fine.
>>
>>the problem is with updatetime. they want me to use the servers time instead of the users time, so they don't want me updating that field in the ui, so it gets passed in as null.
>>
>>It is my understanding that the update of the record that the constraint fires before the trigger does. How do you solve this?
>
>AFTER UPDATE triggers fire after the update happens (but in the same transaction). So, create an AFTER UPDATE trigger to update your UpdateTime column with CURRENT_TIMESTAMP and all should be good.

but won't the not null constraint cause an error if it tries to update with a null value coming in?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform