SlideShare a Scribd company logo
2
Most read
8/10/13 SQL INSERT Statement
beginner-sql-tutorial.com/sql-insert-statement.htm 1/2
SQL INSERT Statement
The INSERT Statement is used to add new rows of data to a table.
We can insert data to a table in two ways,
1) Inserting the data directly to a table.
Syntax for SQL INSERT is:
INSERT INTO TABLE_NAME
[ (col1, col2, col3,...colN)]
VALUES (value1, value2, value3,...valueN);
col1, col2,...colN -- the names of the columns in the table into which you want to insert data.
While inserting a row, if you are adding value for all the columns of the table you need not specify the column(s)
name in the sql query. But you need to make sure the order of the values is in the same order as the columns in
the table. The sql insert query will be as follows
INSERT INTO TABLE_NAME
VALUES (value1, value2, value3,...valueN);
For Example: If you want to insert a row to the employee table, the query would be like,
INSERT INTO employee (id, name, dept, age, salary location) VALUES (105, 'Srinath',
'Aeronautics', 27, 33000);
NOTE:When adding a row, only the characters or date values should be enclosed with single quotes.
If you are inserting data to all the columns, the column names can be omitted. The above insert statement can
also be written as,
INSERT INTO employee
VALUES (105, 'Srinath', 'Aeronautics', 27, 33000);
Inserting data to a table through a select statement.
Syntax for SQL INSERT is:
INSERT INTO table_name
[(column1, column2, ... columnN)]
SELECT column1, column2, ...columnN
FROM table_name [WHERE condition];
For Example: To insert a row into the employee table from a temporary table, the sql insert query would be
like,
INSERT INTO employee (id, name, dept, age, salary location) SELECT emp_id, emp_name,
dept, age, salary, location
8/10/13 SQL INSERT Statement
beginner-sql-tutorial.com/sql-insert-statement.htm 2/2
FROM temp_employee;
If you are inserting data to all the columns, the above insert statement can also be written as,
INSERT INTO employee
SELECT * FROM temp_employee;
NOTE:We have assumed the temp_employee table has columns emp_id, emp_name, dept, age, salary, location
in the above given order and the same datatype.
IMPORTANT NOTE:
1) When adding a new row, you should ensure the datatype of the value and the column matches
2) You follow the integrity constraints, if any, defined for the table.

More Related Content

What's hot (17)

PDF
Structured query language(sql)
Huda Alameen
 
PPTX
SQL Data Manipulation
khalid alkhafagi
 
PPTX
MULTIPLE TABLES
ASHABOOPATHY
 
PPTX
Lab3 aggregating data
Balqees Al.Mubarak
 
PPTX
Lab5 sub query
Balqees Al.Mubarak
 
PPT
Les02 (restricting and sorting data)
Achmad Solichin
 
ODP
Babitha2.mysql
banubabitha
 
PPT
SQL Introduction to displaying data from multiple tables
Vibrant Technologies & Computers
 
PPT
Les09 (using ddl statements to create and manage tables)
Achmad Solichin
 
PPTX
Oracle: Basic SQL
DataminingTools Inc
 
PPTX
Lab4 join - all types listed
Balqees Al.Mubarak
 
PPT
Single row functions
Balqees Al.Mubarak
 
PDF
SQL Functions and Operators
Mohan Kumar.R
 
PDF
Introduction to oracle functions
Nitesh Singh
 
PPTX
Commands
Ayushi Goyal
 
PDF
Writing Group Functions - DBMS
Solaiman Hridoy
 
PPT
Sql DML
Vikas Gupta
 
Structured query language(sql)
Huda Alameen
 
SQL Data Manipulation
khalid alkhafagi
 
MULTIPLE TABLES
ASHABOOPATHY
 
Lab3 aggregating data
Balqees Al.Mubarak
 
Lab5 sub query
Balqees Al.Mubarak
 
Les02 (restricting and sorting data)
Achmad Solichin
 
Babitha2.mysql
banubabitha
 
SQL Introduction to displaying data from multiple tables
Vibrant Technologies & Computers
 
Les09 (using ddl statements to create and manage tables)
Achmad Solichin
 
Oracle: Basic SQL
DataminingTools Inc
 
Lab4 join - all types listed
Balqees Al.Mubarak
 
Single row functions
Balqees Al.Mubarak
 
SQL Functions and Operators
Mohan Kumar.R
 
Introduction to oracle functions
Nitesh Singh
 
Commands
Ayushi Goyal
 
Writing Group Functions - DBMS
Solaiman Hridoy
 
Sql DML
Vikas Gupta
 

Viewers also liked (14)

PPTX
6. triggers
Amrit Kaur
 
PDF
[Www.pkbulk.blogspot.com]dbms11
AnusAhmad
 
PDF
Sql create table statement
Vivek Singh
 
PPTX
SAP HANA - Manually to insert_data_table
Yasmin Ashraf
 
PDF
Sql wksht-7
Mukesh Tekwani
 
ODP
Sql commands
Balakumaran Arunachalam
 
PPT
Sql – Structured Query Language
pandey3045_bit
 
PDF
Part 15 triggerr
Denny Yahya
 
PDF
Sql update statement
Vivek Singh
 
PDF
Sql delete, truncate, drop statements
Vivek Singh
 
PPT
Oracle Database Trigger
Eryk Budi Pratama
 
PPT
SQL Tutorial - How To Create, Drop, and Truncate Table
1keydata
 
PPTX
T-SQL Overview
Ahmed Elbaz
 
ODP
Open Gurukul Language PL/SQL
Open Gurukul
 
6. triggers
Amrit Kaur
 
[Www.pkbulk.blogspot.com]dbms11
AnusAhmad
 
Sql create table statement
Vivek Singh
 
SAP HANA - Manually to insert_data_table
Yasmin Ashraf
 
Sql wksht-7
Mukesh Tekwani
 
Sql – Structured Query Language
pandey3045_bit
 
Part 15 triggerr
Denny Yahya
 
Sql update statement
Vivek Singh
 
Sql delete, truncate, drop statements
Vivek Singh
 
Oracle Database Trigger
Eryk Budi Pratama
 
SQL Tutorial - How To Create, Drop, and Truncate Table
1keydata
 
T-SQL Overview
Ahmed Elbaz
 
Open Gurukul Language PL/SQL
Open Gurukul
 
Ad

Similar to Sql insert statement (20)

PPTX
DML Commands in Database Management System.pptx
chintanraval26
 
PPTX
DML Statements.pptx
UnitedGamer1
 
DOCX
SQL Language
Baker Ahimbisibwe
 
PDF
full detailled SQL notesquestion bank (1).pdf
yvpachorib23
 
PPTX
2..basic queries.pptx
MalaikaRahatQurashi
 
DOCX
unit-5 sql notes.docx
RaviRajput416403
 
PPTX
SQl data base management and design
franckelsania20
 
PPT
CE 279 - WRITING SQL QUERIES umat edition.ppt
minusahsaaka
 
PPTX
Lesson 6 Information Management for BSIT.pptx
EllenGracePorras
 
PDF
DBMS.pdf
Rishab Saini
 
DOC
ORACLE PL/SQL TUTORIALS - OVERVIEW - SQL COMMANDS
Newyorksys.com
 
PPTX
06.01 sql select distinct
Bishal Ghimire
 
PPTX
Lecture 21 Insert Update Delete.pptx
iqbalirtza
 
PPTX
SQL - DML and DDL Commands
Shrija Madhu
 
PDF
Sql
satu2412
 
PDF
SQL notes 1.pdf
JitendraYadav351971
 
PPTX
SQL DATABASE MANAGAEMENT SYSTEM FOR CLASS 12 CBSE
sdnsdf
 
PPTX
ADV PPT 2 LAB.pptx
ArjayBalberan1
 
PPTX
Sql
Aman Lalpuria
 
DOC
Complete Sql Server querries
Ibrahim Jutt
 
DML Commands in Database Management System.pptx
chintanraval26
 
DML Statements.pptx
UnitedGamer1
 
SQL Language
Baker Ahimbisibwe
 
full detailled SQL notesquestion bank (1).pdf
yvpachorib23
 
2..basic queries.pptx
MalaikaRahatQurashi
 
unit-5 sql notes.docx
RaviRajput416403
 
SQl data base management and design
franckelsania20
 
CE 279 - WRITING SQL QUERIES umat edition.ppt
minusahsaaka
 
Lesson 6 Information Management for BSIT.pptx
EllenGracePorras
 
DBMS.pdf
Rishab Saini
 
ORACLE PL/SQL TUTORIALS - OVERVIEW - SQL COMMANDS
Newyorksys.com
 
06.01 sql select distinct
Bishal Ghimire
 
Lecture 21 Insert Update Delete.pptx
iqbalirtza
 
SQL - DML and DDL Commands
Shrija Madhu
 
SQL notes 1.pdf
JitendraYadav351971
 
SQL DATABASE MANAGAEMENT SYSTEM FOR CLASS 12 CBSE
sdnsdf
 
ADV PPT 2 LAB.pptx
ArjayBalberan1
 
Complete Sql Server querries
Ibrahim Jutt
 
Ad

More from Vivek Singh (20)

PPS
C programming session 14
Vivek Singh
 
PPS
C programming session 13
Vivek Singh
 
PPS
C programming session 11
Vivek Singh
 
PPS
C programming session 10
Vivek Singh
 
PPS
C programming session 08
Vivek Singh
 
PPS
C programming session 07
Vivek Singh
 
PPS
C programming session 05
Vivek Singh
 
PPS
C programming session 04
Vivek Singh
 
PPS
C programming session 02
Vivek Singh
 
PPS
C programming session 01
Vivek Singh
 
PPS
C programming session 16
Vivek Singh
 
PDF
Niit aptitude question paper
Vivek Singh
 
PDF
Excel shortcut and tips
Vivek Singh
 
PDF
Sql where clause
Vivek Singh
 
PDF
Sql tutorial, tutorials sql
Vivek Singh
 
PDF
Sql subquery
Vivek Singh
 
PDF
Sql select statement
Vivek Singh
 
PDF
Sql rename
Vivek Singh
 
PDF
Sql query tuning or query optimization
Vivek Singh
 
PDF
Sql query tips or query optimization
Vivek Singh
 
C programming session 14
Vivek Singh
 
C programming session 13
Vivek Singh
 
C programming session 11
Vivek Singh
 
C programming session 10
Vivek Singh
 
C programming session 08
Vivek Singh
 
C programming session 07
Vivek Singh
 
C programming session 05
Vivek Singh
 
C programming session 04
Vivek Singh
 
C programming session 02
Vivek Singh
 
C programming session 01
Vivek Singh
 
C programming session 16
Vivek Singh
 
Niit aptitude question paper
Vivek Singh
 
Excel shortcut and tips
Vivek Singh
 
Sql where clause
Vivek Singh
 
Sql tutorial, tutorials sql
Vivek Singh
 
Sql subquery
Vivek Singh
 
Sql select statement
Vivek Singh
 
Sql rename
Vivek Singh
 
Sql query tuning or query optimization
Vivek Singh
 
Sql query tips or query optimization
Vivek Singh
 

Recently uploaded (20)

PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
community health nursing question paper 2.pdf
Prince kumar
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 

Sql insert statement

  • 1. 8/10/13 SQL INSERT Statement beginner-sql-tutorial.com/sql-insert-statement.htm 1/2 SQL INSERT Statement The INSERT Statement is used to add new rows of data to a table. We can insert data to a table in two ways, 1) Inserting the data directly to a table. Syntax for SQL INSERT is: INSERT INTO TABLE_NAME [ (col1, col2, col3,...colN)] VALUES (value1, value2, value3,...valueN); col1, col2,...colN -- the names of the columns in the table into which you want to insert data. While inserting a row, if you are adding value for all the columns of the table you need not specify the column(s) name in the sql query. But you need to make sure the order of the values is in the same order as the columns in the table. The sql insert query will be as follows INSERT INTO TABLE_NAME VALUES (value1, value2, value3,...valueN); For Example: If you want to insert a row to the employee table, the query would be like, INSERT INTO employee (id, name, dept, age, salary location) VALUES (105, 'Srinath', 'Aeronautics', 27, 33000); NOTE:When adding a row, only the characters or date values should be enclosed with single quotes. If you are inserting data to all the columns, the column names can be omitted. The above insert statement can also be written as, INSERT INTO employee VALUES (105, 'Srinath', 'Aeronautics', 27, 33000); Inserting data to a table through a select statement. Syntax for SQL INSERT is: INSERT INTO table_name [(column1, column2, ... columnN)] SELECT column1, column2, ...columnN FROM table_name [WHERE condition]; For Example: To insert a row into the employee table from a temporary table, the sql insert query would be like, INSERT INTO employee (id, name, dept, age, salary location) SELECT emp_id, emp_name, dept, age, salary, location
  • 2. 8/10/13 SQL INSERT Statement beginner-sql-tutorial.com/sql-insert-statement.htm 2/2 FROM temp_employee; If you are inserting data to all the columns, the above insert statement can also be written as, INSERT INTO employee SELECT * FROM temp_employee; NOTE:We have assumed the temp_employee table has columns emp_id, emp_name, dept, age, salary, location in the above given order and the same datatype. IMPORTANT NOTE: 1) When adding a new row, you should ensure the datatype of the value and the column matches 2) You follow the integrity constraints, if any, defined for the table.