SQL Insert Statement, SQL Tutorial, Global Guide Line Technology.
Forum | Blog |


Basic SQL Guide.           
SQL Introduction.               
 What is Table?                  
 SQL Create Table.            
 SQL Insert Statement.
 SQL Select Keyword.        
 SQL Order by clause.        
 SQL Count Statement.      
 SQL Group By Clause.      
 SQL Having Clause.          
 SQL Alias Tables.             
 SQL Join Tables.              
 SQL Outer Join.               
 SQL Update Statement.   
 SQL Delete Statement.    
 SQL Distinct Keyword.      
 SQL Where Keyword.       
 SQL And Or Keyword.      
 SQL In Keyword.              
 SQL Between Keyword.   
 SQL Like Keyword.          
 SQL Functions.                
 SQL Concatenate.           
 SQL Substrings.               
 SQL Trim Function.         
 SQL Constraints.              
 SQL Primary Key.            
 SQL Foreign Key.            
 SQL Create Views.           
 SQL Create Index.           
 SQL Alter Table.             
 SQL Drop Table.             
 SQL Truncate Table.      
 SQL Summary.                

SQL Tutorial >> SQL Insert Statement.

     Back             Next     

Here in SQL Tutorial you will learn that how do these rows of data get into these tables in the first place? This is what this section, covering the INSERT statement, and next section, covering table Select statement, how to select the stored information from database table.

In SQL, there are essentially basically two ways to INSERT data into a table: One is to insert it one row at a time, the other is to insert multiple rows at a time. Let's first look at how we may INSERT data one row at a time:

Syntax for SQL Insert Statement

INSERT INTO "table_name" ("column1", "column2", ...)
VALUES ("value1", "value2", ...)

Assuming that we have a table that has the following structure,

Table Employees

Column Name Data Type
first_name char(50)
last_name char(50)
phone integer
DBO datetime

and now we wish to insert one additional row into the table representing the information of a new employee with his first name, last name phone number and date of birth. We will hence use the following SQL script: for insert into table.

INSERT INTO Employees (first_name, last_name, phone, DBO)
VALUES ('Austin', 'Hennery', 4461022222,'24/11/1978')

The second type of INSERT INTO statement allows us to insert multiple rows into a table. Unlike the previous example, where we insert a single row by specifying its values for all columns, we now use a SELECT statement to specify the data that we want to insert into the table. We will discus the Select statement in next lesson with details. If you are thinking whether this means that you are using information from another table, you are correct. The syntax is as follows:

INSERT INTO "table1" ("column1", "column2", ...)
SELECT "column3", "column4", ...
FROM "table2"

Note that this is the simplest form. The entire statement can easily contain WHERE, GROUP BY, and HAVING clauses, as well as table joins and aliases.
So for example, if we wish to have a table, Employees, that contains the information of employees, and you already know that the source data resides in the Old_Employees table, we'll type in:

INSERT INTO Employees (first_name, last_name, phone, DBO)
SELECT first_name, last_name, phone, DBO
FROM Old_Employees
WHERE Gender ='f'

Here we have used the SQL Server syntax to extract the information from the Old_Employees and the condition is used here that only female employees records will be inserted into the Employees table.  Hope this SQL Tutorial section is enough to build a ground for SQL Insert Statement for the beginners of SQL Developers.

     Back             Next     

[ About ] [ Contact ] [ Home ]
[ Links ] [ Site Map ] [ Services ] [ Privacy ]

Copyright 2005 -  2022 www.globalguideline.com All rights reserved. (Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher) 313 visitors are online now