CLASSXI_XLL_INSERT

  CLASS XI-XII

(SQL INSERT INTO STATEMENT )


SQL INSERT INTO Statement
The INSERT INTO statement is used to insert new records in a table.

INSERT INTO Syntax

It is possible to write the INSERT INTO statement in two ways.
The first way specifies both the column names and the values to be inserted:
METHOD 1:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
METHOD2:
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
HOW TO INSERT THE RECORDS IN A TABLE DVD
Method 1:
INSERT INTO DVD(DCODE,DTITLE,DTYPE) VALUES(“F101”,”Henry Martin”,”Folk”)
Method2:
INSERT INTO DVD VALUES(“F101”,”Henry Martin”,”Folk”)

EXAMPLE:
TO CREATE A TABLE CUSTOMERS WITH THE FOLLOWING FIELDS :

ID INTEGER PRIMARY KEY
NAME VARCHAR 25 NOT NULL
AGE INTEGER
ADDRESS VARCHAR 25
SALARY DECIMAL 6,2

CREATE TABLE CUSTOMERS
(
ID INT PRIMARY KEY,
NAME VARCHAR(25) NOT NULL,
AGE INT,
ADDRESS VARCHAR(25),
SALARY DECIMAL(6,2)
);


AFTER CREATING A TABLE STRUCTURE NEXT PART IS TO INSERT THE RECORD IN AN EMPTY TABLE:


INSERT INTO CUSTOMERS VALUES (1, 'Ramesh', 32, 'Ahmedabad', 2000.00 );

IF WE CHECK THE CUSTOMER TABLE ONE RECORD IS STORED.

ID
 NAME    
 AGE
 ADDRESS  
 SALARY  
1
Ramesh
32
Ahmedabad
2000.00


INSERT INTO CUSTOMERS VALUES (2, 'Khilan', 25, 'Delhi', 1500.00 );
IF WE CHECK THE CUSTOMER TABLE AGAIN.

ID
 NAME    
 AGE
 ADDRESS  
 SALARY  
1
Ramesh
32
Ahmedabad
2000.00
2
Khilan
25
Delhi
1500.00

This is another method or inserting the record by using the field name after customers table name inside the brackets:

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (3, 'kaushik', 23, 'Kota', 2000.00 );

ID
 NAME    
 AGE
 ADDRESS  
 SALARY  
1
Ramesh
32
Ahmedabad
2000.00
2
Khilan
25
Delhi
1500.00
3
Kaushik
23
Kota
2000.00
What is the use of writing the field or column names?
Ans:It is use to Insert Data Only in Specified Columns.

Q. If I write this line to insert the record in customers table it is correct line or not.

INSERT INTO CUSTOMERS VALUES ('Hardik',6500.00,'Mumbai',32,4);


Followers

Popular Posts

Recent Posts