MySQL INSERT statement is used to insert data in MySQL table within the database. We can insert single or multiple records using a single query in MySQL.
INSERT INTO table_name ( field1, field2,...fieldN )
( value1, value2,...valueN );
Field name is optional. If you want to specify partial values, field name is mandatory.
Syntax for all fields:-
INSERT INTO table_name VALUES ( value1, value2,...valueN );
If you have to store all the field values, either specify all field name or don't specify any field.
insert into empvalues(103,'Shweta','Manager',30000);
INSERT INTO emp(EmpId,EmpName,EmpJob,salary)
VALUES (104, ’Lata',’Admin’, 20000);
MySQL INSERT Example 2: for partial fields:-
In such case, it is mandatory to specify field names.
insert into Emp(EmpId,EmpName)values(201,'Tuntun');
Here, we are going to insert record in the “Emp" table of “College" database.
insert into Emp(EmpId,EmpName,EmpJob,Salary)
MySQL UPDATE Query:-
MySQL UPDATE statement is used to update data of the MySQL table within the database. In real life scenario, records are changed over the period of time. So, we need to make changes in the values of the tables also. To do so, we need to use the UPDATE statement.
The UPDATE statement is used with the SET, and WHERE clauses. The SET clause is used to change the values of the specified column. We can update single or multiple columns at a time. The WHERE clause is used to specify the condition, but it is optional.
SET field1=new-value1, field2=new-value2, ...
One or more field can be updated altogether.
Any condition can be specified by using WHERE clause.
You can update values in a single table at a time.
WHERE clause is used to update selected rows in a table.
Here, we have a table “Emp" within the database “College".
We are going to update the data within the table “Emp".
This query will update EmpJob field for a record having EmpID as 5.
update EmpSEt EmpName='Kareena‘
MySQL DELETE statement is used to delete data from the MySQL table within the database. By using delete statement, we can delete records on the basis of conditions.
DELETE FROM table_name
Delete From Emp