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 |
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2012-05-09 : 13:14:59
|
Hi AllThere is a need to add a new column(SystemDate) in an Existing Table(customerInfo).The new column should automatically get populated with sysdate at the time of a record gets insertedWhat would be the Alter script for the new column.I used the below script and it is not correctALTER TABLE CustomerInfoADD SystemDate as (getdate ( )) Thanks |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-05-09 : 13:22:59
|
Maybe this weill help get you goingALTER TABLE dbo.CustomerInfoADD SystemDate DATETIME2(2) CONSTRAINT DF_CustomerInfo_SystemDate DEFAULT (getdate()) NOT NULL |
 |
|
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2012-05-09 : 14:47:33
|
| Thank You.It worked |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-09 : 15:54:41
|
quote: Originally posted by jim_jim Thank You.It worked
please keep in mind that defaults wont get applied for updates so you've explicitly pass the value for this column in update statements to get it changed------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|