Format function in sqlserver


SqlServer, SqlServer Useful functions

FORMAT FUNCTION

 

Some times it so happens that we have  many leading zeros after a decimal number .

For example I am getting a result of a query say value of closing stock  as 66000.000000 .

However I need to keep only 2 zeros after the decimal point and want the result as 66000.00 .

Here is a common trick of using the Format function.


Read More...

Enable and Disable Constraints


SqlServer, SqlServer Useful functions
The best way to insert valid data is with constraints. This is also known as data enforcing data or data integrity. We already know that there are various types of constraints in SQL Server. They are:
  1. Primary key constraint
  2. Default key Constraint
  3. Check Constraint
  4. Foreign key Constraint
  5. Unique key Constraint

Sometimes we need to disable constraints to work with...Here is how to do it


Read More...

Resetting Identity Column Value


SqlServer, SqlServer Useful functions

Identity column of a table is a column whose value increases automatically. A user generally cannot insert a value into an identity column. A table can have only one column that is defined with the identity attribute.

Syntax :

IDENTITY [ ( seed , increment ) ]

Default value of identity is IDENTITY (1,1).

Seed : The seed represents the starting value of an ID and the default value of seed is 1.

Increment : It will represent the incremental value of the ID and the default value of increment is 1.


Read More...