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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Default column value

Author  Topic 

SammyWaslow
Starting Member

9 Posts

Posted - 2006-08-22 : 10:31:34
I try to set the default value of a column 'DateAdded' to
ISNULL(dateAdded,getdate())

However, this results in an errormsg. Why is that ?
I suspect the column name is not recognized as such? How Do I format the column name (DateAdded) ?

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-08-22 : 10:43:26
you set the default value to Getdate() not isnull(...)



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

SammyWaslow
Starting Member

9 Posts

Posted - 2006-08-22 : 11:07:15
I know that!

But what I want is to set the default value to getdate() only if the column is null!
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-08-22 : 11:31:09
huh?
with default value the column will never be null...



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

SammyWaslow
Starting Member

9 Posts

Posted - 2006-08-22 : 11:38:00
The idea is that on record creation getdate() is executed as defaultvalue for DateAdded. After that the value may not be updated!
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-08-22 : 11:53:22
You want the column to be "read-only"?
Create a trigger that denies all changes to the column.


(I can't believe I am suggesting this...)


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-08-22 : 12:19:43
why would you want to update it anyway?




Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

SammyWaslow
Starting Member

9 Posts

Posted - 2006-08-23 : 03:29:42
Basiscly I want the column to contain the date the record was created (inserted)
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-08-23 : 04:46:04
then just put getdate() in the default value.
denying approach on the table level is a wrong approach.



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-08-23 : 05:20:38
Oh, you mean (according to your second post)

UPDATE MYTABLE SET DATEADDED = GETDATE() WHERE DATEADDED IS NULL?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -