SQL INSERT

      Comments Off on SQL INSERT

The SQL INSERT INTO Statement is used to add new rows of data to a table in the database.

Syntax:

  • INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)  
    VALUES (value1, value2, value3,...valueN);
    
  • INSERT INTO TABLE_NAME VALUES (value1, value2, value3,... valueN );
    

Demo database: Customers

C.idC.nameC.contactC.address
123eed3Ramesh987654321#12,sec-4 mohali
aa22103Tarun987650000#12,sec-14 b chd
00146hhSia812300912#212,sec-86 panchukula
144dcv4Rahul700912366#001,sec-19 c chd

SQL INSERT examples:

INSERT INTO CUSTOMERS (C.id, C.name, C.contact, C.address) VALUES ('aa23120a', 'Bani' ,981234577, '#45, colony abc')

Result:

C.idC.nameC.contactC.address
123eed3Ramesh987654321#12,sec-4 mohali
aa22103Tarun987650000#12,sec-14 b chd
00146hhSia812300912#212,sec-86 panchukula
144dcv4Rahul700912366#001,sec-19 c chd
aa23120aBani981234577#45, colony abc

INSERT INTO CUSTOMERS VALUES ('vc4100a', 'Rita ora' ,01234555, '#01, colony sde')

Result:

C.idC.nameC.contactC.address
123eed3Ramesh987654321#12,sec-4 mohali
aa22103Tarun987650000#12,sec-14 b chd
00146hhSia812300912#212,sec-86 panchukula
144dcv4Rahul700912366#001,sec-19 c chd
aa23120aBani981234577#45, colony abc
vc4100aRita ora01234555#01, colony sde