Adding Default values to an table.

Default values are automatically added to table if no other values are specified by user. This is shown as below.

create database noteDatabase
use noteDatabase
go
create table OrderItem(
	Id int identity(1,1),
	ProductName nvarchar(100),
	MinOrder int default 10,
	ProductPrice float,
);
insert into dbo.OrderItem values('battery',12,2000)
insert into dbo.OrderItem(ProductName,ProductPrice) values ('charger',100)
select * from dbo.OrderItem
 
  


To view or add a comment, sign in

More articles by ashish khatiwada

  • Cursors in Sql Server

    Let's first create a table and use that table in cursor. CREATE TABLE [dbo].

  • Stored Procedure in Sql Server

    Executing stored procedure is faster than executing statements. Before creating Stored procedure first create a table…

  • Using multiple inner Join

    Inner Join only shows those data which satisfy the given statement after on keyword. To perform multiple join action…

  • Where to use Go command in sql server

    As shown above both the two sql statements are correct if they are executed one statement at a time but it throws an…

  • Maintaining Relationships in Database

    MAINTAINING ONE TO ONE RELATIONSHIPS Here I am creating two tables first named as tblPerson and Contact and these…

  • Advancing the check constraint in Microsoft SqlServer.

    /* Let's begin with creating table with a check constraint and adding a primary key by combining two columns. combining…

Explore content categories