The INSERT INTO statement is used to insert new records in a table.
Create a Database named "Studysql" and a table named "tbl_biodata"
Right click on the database Studysql and select new query.Then we can write queries as per the requirements.
( Click here to know how created this table )
The created Table is :
Create a Database named "Studysql" and a table named "tbl_biodata"
Right click on the database Studysql and select new query.Then we can write queries as per the requirements.
( Click here to know how created this table )
ID
|
NAME
|
AGE
|
CITY
|
PHONE
|
1
|
Priyada
|
25
|
Cochin
|
1000000001
|
2
|
Mohan
|
30
|
Cochin
|
2000000002
|
3
|
Jaimon Jacob
|
40
|
Vytila
|
3000000003
|
4
|
Sumith
|
24
|
Kottayam
|
4000000004
|
5
|
Shaiju
|
36
|
Thrissur
|
5000000005
|
We can write the INSERT INTO statement in two forms.
1 : Insert Data without specifying column names :
The first form doesn't specify the column names where the data will be inserted, only their values:
Now we want to insert a new row in the "biodata" table.
To do so, write the command like this in SQL.
INSERT INTO tbl_biodata VALUES
('Arya', '25', 'Cochin', '6000000006')
|
Here, as per the above given table format , I inserted a new row (6th row) .
When executing , we can see a message :
Then exit from the Query window , and come to tbl_biodata, then we can see 5 records are there
Select EXECUTE ( see the figure below ) , to view the inserted new row .
The result-set will look like this:
Note , the symbol used for executing .Or you can select the EXECUTE option from the menu " QUERY DESIGNER " .
SQL SELECT Syntax of the above table is :
INSERT INTO table_name
VALUES (value1, value2, value3,...)2 : Insert Data Only in Specified Columns :
The second form specifies both the column names and the values to be inserted:
Now we want to insert a new row in the "biodata" table , in a specific column.
To do so, write the command like this in SQL.
When executing we can see ,
The result-set will look like this:
To do so, write the command like this in SQL.
INSERT INTO tbl_biodata (names, age) VALUES ('Reshmi', '23')
|
When executing we can see ,
The result-set will look like this:
No comments:
Post a Comment