ddsingh@infomatics.info +91 9760014754

DML Statement

MySQL INSERT Statement:-

  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.

Syntax:-

INSERT INTO table_name ( field1, field2,...fieldN )  

VALUES  

( value1, value2,...valueN );  

Note:-

     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 );

 

MySQL INSERT Example 1: for all fields:-

  If you have to store all the field values, either specify all field name or don't specify any field.

Ex:-

insert into empvalues(103,'Shweta','Manager',30000);

Or,

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.

 

Ex:-

 

insert into Emp(EmpId,EmpName)values(201,'Tuntun');

MySQL INSERT Example 3: inserting multiple records:-

 

  Here, we are going to insert record in the “Emp" table of “College" database.

 insert into Emp(EmpId,EmpName,EmpJob,Salary)

Values

(202,'Lata','Admin',2000),

(203,'Lata','Admin',2000),

(204,'Lata','Admin',2000);

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.

Syntax:-

UPDATE table_name   

SET field1=new-value1, field2=new-value2, ...  

[WHERE Clause]  

 

Note:-

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.

Example:

     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

where empid=203;

Ex:-

 

update Emp

SET EmpName='Ameesha',EmpJob='Actress‘

where empid=204;

MySQL DELETE Statement:-

    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.

 

Syntax:-

 

DELETE FROM table_name   

WHERE  

(Condition specified);  

Ex:-

Delete From Emp

Where EmpID=204;

 

 

 


Prev Next