SQL-Insert Statemnet


Insert: Insert Statement is used to insert values in tables. In Insert Statement the number of columns and values must be the same. If a column is not specified, the default value for the column is used. 

SQL Syntax would be as follows: 
Insert into tablename (column1, column2, column3) values (value1, value2, value3)

                                          (Or)
Insert into table name values (value1, value2, value3)


By using these two statements we can insert required data to the required table.


Example for Insert Statement:
Insert into Employee (empid, First Name, Last Name, Deportment, Address, City) values (001,’sam’, ‘Prasad’, ‘QA’, ‘XYZ Automobiles’, ’Delhi’);
After running the query "Employee" table will now look like this:





empid
First Name
Last Name
Deportment
Address
City
 001
 sam
prasad 
 QA
XYZ Automobiles 
 Delhi























It is not need to specify the all column(s) name in the SQL query if we are adding values for all the columns of the table. But make sure the order of the values is in the same of order as the columns in the table.
Insert into Employee values (001,’sam’, ‘Prasad’, ‘XYZ Automobiles’);
Table name is Employee
After running the Second query "Employee" table will now look like this:





empid
First Name
Last Name
Deportment
Address
City
 001
 sam
Prasad 

XYZ Automobiles  


































SQL Syntax

For  Quick View we are giving SQL syntax here:

1)SQL Create Database Syntax:
Create Database database name;


2)SQL Drop Database Syntax:
Drop Database database name;


3)SQL Create Table Syntax:
Insert into table name (Column Name1 data type(size), Column Name1 data type(size), Column Name2 data type(size), Column Name3 data type(size));

Insert into table name values(valur1,valu2,value3;)


3)SQL Update Table Syntax:
Upadate Table table name (Column Name1 data type(size), Column Name1 data type(size), Column Name2 data type(size), Column Name3 data type(size));


4)Syntax for SELECT Statement:
If we want to select all columns form the table then the SQL query will be
Select * from tablename;

If we want to select selected columns form the table then the SQL query will be
Select column1, column2, column5 from tablename;


5)SQL WHERE Clause:
Select column1, column2, column5 from tablename where (Condiation);


Over View of SQL

SQL (Structured Query Language) is a special-purpose programming language designed for storing, manipulating and retrieving data stored in a Relational Database Management System (RDBMS).SQL consists of a data definition language and a data manipulation language. SQL became a standard of the American National Standards Institute (ANSI) in 1986 and of the International Organization for Standardization (ISO) in 1987. Since then, the standard has been enhanced several times with added features. Most Relational Database Management Systems like MS SQL Server, Microsoft Access, Oracle, MySQL, DB2, Sybase, PostgreSQL and Informix use SQL as a database querying language.
Different Products of RDMS are:

Oracle
Oracle Corporation
SQL Server 2000
Microsoft Corporation
DB2 UDB
IBM
My SQL
My SQL
Sybase
Sybase

                               In SQL we have standard commands to interact with Relational Database. Those commands are Create, Alter, Truncate, and Drop. These Commands can be classified into groups based on their nature.

1)     DDL - Data Definition Language
2)     DML- Data Manipulation Language
3)     DQL- Data Query Language
4)     DCL- Data Control Language
5)     TCL- Transaction Control Language

1)DDL - Data Definition Language: These Statements (Commands) are used to Create, Insert, Modify and Drop Database Objects.
Some Examples:
a)      Create: Create Statement is used to make a new database, table, index, or stored procedures.
By using Create Statement we are creating a table in Database. Tables are organized into rows and columns.
Syntax for Create Statement:
Create Table  tablename (Column Name1 data type(size), Column Name1 data type(size), Column Name2 data type(size), Column Name3 data type(size), ………);
Here:
§  The column name represents specify the names of the columns of the table.
§  The data type parameter represents which type of data the column can hold (e.g. varchar integer, date etc.).
§  The size parameter represents the maximum length of the column of the table.

Example for Create Statement:
 Create Table Employee (empid  int (20), First Name Varchar(50), Last Name Varchar(50), Deportment varchar(50), Address Varchar(50),City Varchar (50));

Table name is Employee
In this table empid column is represents int data type and it will hold an integer Value. Last Name, First Name, Deportment, Address and City columns are of type varchar and will hold characters, and the maximum length for these fields is 50 characters. 

The empty "Employee" table will now look like this:





empid
First Name
Last Name
Deportment
Address
City





























2)    DML- Data Manipulation Language: These Statements (Commands) are used to Insert, Update and Delete Database Objects. 
      3)  DQL- Data Query Language: These Statements (Commands) are used  Select Commands 
     4)  DCL- Data Control Language: These Statements (Commands) are used to create roles, permissions, and referential integrity as well it is used to control access to database by securing it.
Examples: GRANT, REVOKE statements
5)   TCL- Transaction Control Language: These Statements (Commands) are used to manage different transactions occurring within a database.
Examples: COMMIT, ROLLBACK statements