0% found this document useful (0 votes)
19 views3 pages

My SQL - 11.11.24

Uploaded by

jagavike65
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

My SQL - 11.11.24

Uploaded by

jagavike65
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Day 6: DBMS - MYSQL Date: 11.11.

24

Data Manipulation Language (DML) is a subset of SQL commands used to interact with and
manipulate data stored in a database. DML statements allow users to insert, update, delete, and
retrieve data within tables. Unlike Data Definition Language (DDL), which defines the structure of
the database, DML focuses on managing the actual data in the database.

Key DML commands include:

 INSERT INTO – Adds new records to a table.


 UPDATE – Modifies existing records.
 DELETE – Removes records from a table.
 SELECT – Retrieves data from one or more tables.

DML commands are essential for managing and accessing the data within a relational database.

1. Inserting Data: INSERT INTO

The INSERT INTO statement adds new rows to a table. It specifies the table, columns, and values to
insert.

sql
Copy code
INSERT INTO table_name (column1, column2) VALUES (value1, value2);

2. Updating Data: UPDATE

The UPDATE statement modifies existing data in a table. It specifies the table, columns to update, new
values, and conditions.

sql
Copy code
UPDATE table_name SET column1 = value1 WHERE condition;

3. Deleting Data: DELETE

The DELETE statement removes rows from a table based on specified conditions.

sql
Copy code
DELETE FROM table_name WHERE condition;
4. Basic SELECT Queries

The SELECT statement retrieves data from a table. It specifies columns to retrieve and conditions to
filter rows.

sql
Copy code
SELECT column1, column2 FROM table_name WHERE condition;

These commands help manage data within a database by allowing you to add, modify, remove, and
retrieve records.

Home Work:

1. Write a query to order employees by their salary in descending order.

2. Write a query to count the number of employees in each department.

3. Write a query to find the maximum salary in the employees table.

4. Develop an ER diagram for a library system with entities like Book, Member, Author, and Loan.
Define relationships such as Borrows (between Member and Book), Writes (between Author
and Book), and Reserves (between Member and Book).

MySQL Oueries for workbench practice :

1. Inserting Data: INSERT INTO

1. Insert a new customer named "Alice Smith" with a customer ID of 101 into the "customers"
table.

INSERT INTO customers (customer_id, name) VALUES (101, 'Alice Smith');

2. Add a product with an ID of 5, name "Laptop", and price of 1000 to the "products" table.

INSERT INTO products (product_id, name, price) VALUES (5, 'Laptop', 1000);
2. Updating Data: UPDATE

1. Update the price of the product with ID 5 to 1200 in the "products" table.

UPDATE products SET price = 1200 WHERE product_id = 5;

2. Change the name of the customer with customer ID 101 to "Alice Johnson" in the
"customers" table.

UPDATE customers SET name = 'Alice Johnson' WHERE customer_id = 101;

3. Deleting Data: DELETE

1. Delete the customer with customer ID 101 from the "customers" table.

DELETE FROM customers WHERE customer_id = 101;

2. Remove the product with product ID 5 from the "products" table.

DELETE FROM products WHERE product_id = 5;

4. Basic SELECT Queries

1. Retrieve the names of all customers from the "customers" table.

SELECT name FROM customers;

2. Select all details of products priced over 500 from the "products" table.

SELECT * FROM products WHERE price > 500;

You might also like