DEFAULT constraint in sql server

DEFAULT – This constraint provides a default value when specified none for this column.

Example-
Following create a table PRODUCT, column DTCREATE has default value GETDATE() it will store the system’s date-time by default if the value is not specified for this column.

CREATE TABLE PRODUCT
(
ID INT NOT NULL,
SKU VARCHAR(20) NOT NULL,
TITLE VARCHAR(200) NOT NULL,
PRICE MONEY NOT NULL,
DESCRIPTION VARCHAR(2000)  NULL,
DTCREATE DATETIME DEFAULT GETDATE()
)

If the PRODUCT table has already been created and you want to apply default price in the PRICE column use the following query (for SQL server).


ALTER TABLE PRODUCT ADD CONSTRAINT DF_SomePrice DEFAULT 20.00 FORPRICE

PostgreSQL-Query: Sort result set by specific field values using ORDER BY Clause

Problem: Suppose we have a book_inventory table which has some columns such as id, isbn, title, author, publisher, publish_date, etc.. whe...