SQL Server Insert

Insert command is used to insert data into a table. SQL Server Insert is one of data manipulation language command. Used to modify the database objects. Strings and date values must be enclosed with single quoted marks.

Syntax:

insert into table_name
(coulmn1, column2) values(value1, value2)

Example:
Create table

CREATE TABLE [dbo].[emp](
[empname] [varchar](20) NULL,
[empno] [numeric](18, 0) NULL,
[job] [varchar](30) NULL,
[joindate] [date] NULL,
[salary] [money] NULL,
[deptno] [nchar](10) NULL,
[location] [nchar](10) NULL
) ON [PRIMARY]

Insert data into above created table ’emp’

insert into emp(empname, empno, job, joindate, salary, deptno, location)
values(‘George’,5999,‘Adminstrator’,
‘2003-07-14’,9000,20,‘Elchuru’)

 

Insert data by GUI method:
 
1). Open SQL Server Management Studio. Then, right click on table to insert data.
SQL-Server-Insert

 
2) Click on Edit top 200 rows and enter the data.
SQL-Server-Insert1
 
Inserting Null values:
Null values can be inserted in two ways
1) Inserting null valus explicitly, we have to specify null in insert statement.
 
example:

insert into emp
values(‘Vane’,8000,null,null,1000,100,null)

2) Inserting null values implicitly can be done by exact columns in the column list respect values in values list.

Powered by k2schools