Sunday 22 November 2015

INSERT command in SQL

INSERT command is used in SQL for inserting or adding the data into the table.

Syntax:

INSERT into <tname> [(<columnlist>)] values (<list of values>)

Table BANK:
Custid
Cname
Balance
1
John
5000
2
Rama
7000

Examples:
1.       INSERT into BANK values (101, ‘Ajay’,5000)
2.       INSERT into BANK (Custid,Cname,Balance) values(102,’Laura’,3500)

Note: String and Date values are enclosed into a single quote only
Query 2 is compiled and executed faster than Query 1.

If you want to INSERT some special values at special column then use query as below:
3.       INSERT into BANK (Custid, Balance) values (107,9000)

It is advised to use Query type 2 or Query type 3.

If the value is not supplied to a column while inserting, the default value is taken as NULL.
4.       INSERT into BANK values (111, NULL, 8700)
You can also explicitly insert NULL values into any column as you required as mentioned in Query 4.




No comments:

Post a Comment