Insert data in sql table
Insert data in SQL table :- For inserting data into a table INSERT INTO statement is used to insert single or multiple records in a table.
There are two ways to insert data in a table:-
- By specifying column names
- Without specifying column names
By specifying column names:- The first way to describe both column names and values to be inserted.
Syntax:-
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
Without specifying column names:- If we want to add values for all the columns of the table, we don't need to specifying column names in the query.
Syntax:-
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
Example:-
The following statements would create six records in the "student" table:-
INSERT INTO student (studentID,Name,Email,Age,city,fees)
VALUES (1, 'Marry', 'mary@gmail.com', 20, 'Delhi', 20000);
INSERT INTO student (studentID,Name,Email,Age,city,fees)
VALUES (1, 'John', 'john@gmail.com', 18, 'Lucknow', 15000);
INSERT INTO student (studentID,Name,Email,Age,city,fees)
VALUES (1, 'Kia', 'Kia@gmail.com', 22, 'Faridabad', 17000);
INSERT INTO student (studentID,Name,Email,Age,city,fees)
VALUES (1, 'Tina', 'Tina@gmail.com', 24, 'Agra', 16000);
INSERT INTO student (studentID,Name,Email,Age,city,fees)
VALUES (1, 'Tad', 'Tad@gmail.com', 22, 'Delhi', 20000);
INSERT INTO student (studentID,Name,Email,Age,city,fees)
VALUES (1, 'Riya', 'Riya@gmail.com', 25, 'Agra', 25000);
OUTPUT:-
You can create a record in the student table by using the second syntax as shown below:-
Example:-
INSERT INTO student
VALUES (7, 'Rahul', 'Rahul@gmail.com',24, 'lucknow', 18000);
OUTPUT:-
Insert data into the specified column:- You can insert data into a specified column by using following SQL statement.
Consider the above table. In this table, we will insert data into Name , Age and fees.
Syntax:-
INSERT INTO student (Name, Age, fees)
VALUES ('Aakash' , 20 , 15000);
Output:-
Comments
Post a Comment