My SQL - 11.11.24
My SQL - 11.11.24
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.
DML commands are essential for managing and accessing the data within a relational database.
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);
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;
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:
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).
1. Insert a new customer named "Alice Smith" with a customer ID of 101 into the "customers"
table.
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.
2. Change the name of the customer with customer ID 101 to "Alice Johnson" in the
"customers" table.
1. Delete the customer with customer ID 101 from the "customers" table.
2. Select all details of products priced over 500 from the "products" table.