To add a function as a default to a column at table creation you must single quote the function name.
Create Table Example |
Copy Code
|
---|---|
CREATE TABLE LogEntries ( EntryID int IDENTITY(1,1) NOT NULL, Entry varchar(8000) NOT NULL, Tags varchar(200) NOT NULL, DateEntered datetime NOT NULL DEFAULT 'GETDATE()', ) |
The DEFAULT 'GETDATE()' is required. You can also type in GETDATE() in the DataBuilder and it will quote the function for you.
To remove the default from a column through SQL you must execute an ALTER TABLE syntax with all the same table parameters, but no default specified.
ALTER TABLE [LogEntries] ALTER COLUMN [DateEntered] datetime NOT NULL;
This would remove the default applied in the statement above.