VistaDB 5
DEFAULT column entries

Adding a default value to a column

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
   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.

Remove Column Default

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.

DEFAULT and Binary Columns

You cannot add defaults to binary type fields. Binary data can only be input through the use of parameterized queries. Trying to put a default on a binary data type (like images, varbinary, etc) will result in invalid inserts to the database. Default values should NOT be used on data types that use binary data.

See Also