Sunday, April 29, 2012

SQL INSERT INTO

Hello Friends, Welcome To this post, and today I will be discussing about the SQL INSERT INTO Query.

Well the name of the query suggests that it something related to inserting into records or data. Well if you thought so you were absolutely right.

Lets see it in action, SQL INSERT INTO query is used to add data or record to a Table.

Lets assume we have a Table named "Employee", where we have 3 columns name "PID", "Name" and "Designation".

PID    Name    Designation
222    Whiskey     Admin
444    Onty          Admin
111    Gaurav       Admin
333    Kumaar     Admin

Syntax of INSERT INTO:

INSERT INTO table_name
VALUES (val1, val2, . . . . .)


So for our Query:

INSERT INTO Employee
VALUES (555, "Rishabh" "Admin")


Our result-set would be:

PID    Name    Designation
222    Whiskey    Admin
444    Onty          Admin
111    Gaurav       Admin
333    Kumaar     Admin
555    Rishabh     Admin

There is another way by which we can insert records by specifying where we want to insert and insert

values respectively .

Syntax:

INSERT INTO table_name (column1, column2, . . . . .)
VALUES (val1, val2 . . . .)


Ex:

INSERT INTO Employee ("Name", "Designation")
VALUES ("Rose", "Admin")


And our result-set would be:

PID    Name    Designation
222    Whiskey    Admin
444    Onty          Admin
111    Gaurav       Admin
333    Kumaar     Admin
555    Rishabh     Admin
Null    Rose         Admin

You have have noticed the column names and values within quotes (""), this is because they are String type data, for numeric data we do not use quotes.

Thats all for this post, hope you enjoyed it and was informative.

Don't forget to check my next post.

Thank You!

0 comments:

Post a Comment