Why do we need default column values in SQL Server? [Resolved]

Posted by Neerajprasadsharma under Sql Server on 5/23/2017 | Points: 10 | Views : 194 | Status : [Member] | Replies : 1
Why do we need default column values in SQL Server?

I write technical articles mainly on SQL Server Query Optimizer for more information look at my BIO.


Responses

Posted by: Neerajprasadsharma on: 5/23/2017 [Member] Bronze | Points: 25

Up
1
Down

Resolved

Default values are prespecified values which are used when the user doesn`t provide the input to the column. It can be useful in various situations, for example :
1. There is a Sales table in your database and on that table there is a column Saledate, which holds the date of the Sale. So in that case you no need to insert the date explicitly in the code, if the sale date`s default value is current date using getdate() function, it will take the current sale date.
2. Default Image Path: you have a user table in your database and you keep the image URL in a user table, then you can use a default Image path in the image path table, so whenever the user does not provide there image default image shows on the website.

3. Default Country: for example a business operates in mainly in a country, but they sometimes do business outside of their county, then they can use the default country name as their head office`s country name.

4. Default Status: website like Dotnetfunda.com uses new user status as
"Starter" even in that case they also might be using the default value:) etc etc...


Default value isn`t a must have or a big problem solver kind of feature, but it`s quite handy and saves some time.



We welcome everybody to contribute to this question answer series.


I write technical articles mainly on SQL Server Query Optimizer for more information look at my BIO.

Neerajprasadsharma, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response