How To Use Column Default Values in INSERT Statements in MS SQL Server?
Submitted by: AdministratorIf a column is defined with a default value in a table, you can use the key word DEFAULT in the INSERT statement to take the default value for that column. The following tutorial exercise gives a good example:
INSERT INTO ggl_links VALUES (102,
'www.globalguideline.com',
NULL,
0,
DEFAULT)
GO
(1 row(s) affected)
SELECT * FROM fyi_links
GO
id url notes counts created
101 www.globalguideline.com NULL 0 2006-04-30
102 www.globalguideline.com NULL 0 2007-05-19
The default value, getdate(), is used for "created" column, which gives the current date.
Submitted by: Administrator
INSERT INTO ggl_links VALUES (102,
'www.globalguideline.com',
NULL,
0,
DEFAULT)
GO
(1 row(s) affected)
SELECT * FROM fyi_links
GO
id url notes counts created
101 www.globalguideline.com NULL 0 2006-04-30
102 www.globalguideline.com NULL 0 2007-05-19
The default value, getdate(), is used for "created" column, which gives the current date.
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | What Happens If NULL Values Are Involved in Bitwise Operations? |
☺ | PHP MSSQL - How To Delete Existing Rows in a Table? |
☺ | What Happens If Strings Are Casted into Wrong Code Pages in MS SQL Server? |
☺ | Can You Roll Back the DDL Statement in a Trigger? |
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |
☺ | Sybase Interview Questions. |