Data Definition Language (DDL) statements in SQL Server are used for defining and managing database objects, including tables. Here's how you create tables:
Data Manipulation Language (DML) statements in SQL Server are used to interact with data within tables. Here's how you can insert data into a table
INSERT INTO
Customers (FirstName, LastName, Email)
VALUES
('John', 'Doe', 'john.doe@example.com');
In this example, a new record is added to the "Customers" table with values for the "FirstName," "LastName," and "Email" columns.
DML statements also allow you to modify existing data in a table. You can use the UPDATE statement for this purpose:
UPDATE
Customers
SET
Email = 'johndoe@example.com'
WHERE
CustomerID = 123;
To remove data from a table, you can use the DELETE statement:
DELETE
FROM
Customers
WHERE
CustomerID = 123;
In this example, a customer record with a specific ID is deleted from the "Customers" table.
● Inserting Data : Add new customer records when users create accounts or insert order records when customers make purchases.
● Updating Data: Modify order statuses when orders are processed and shipped.
● Deleting Data: Remove canceled or returned orders from the database.
● Inserting Data : Insert new product records when new products are added to the inventory.
● Updating Data: Update product quantities when stock is received or sold.
● Deleting Data: Delete outdated product listings that are no longer available.
1. Create a table named "Employees" with columns for employee ID (INT), first name (VARCHAR), last name (VARCHAR), and date of hire (DATE). Define appropriate constraints.
2. Add a new column to the "Products" table called "StockQuantity" to keep track of product stock levels. Set a default value of 0 for this column.
3. Modify the "Customers" table to add a constraint that ensures email addresses are unique.
4. Create a table named "Orders" with columns for order ID (INT), customer ID (INT), order date (DATE), and total amount (DECIMAL). Include primary key and foreign key constraints.
5. In a library database, create a table named "Books" with columns for book ID (INT), title (VARCHAR), author (VARCHAR), and publication date (DATE). Add a constraint to ensure that the title and author together are unique.
Data Definition Language (DDL) statements in SQL Server are used for defining and managing database objects, including tables. Here's how you create tables:
Data Query Language (DQL) statements in SQL Server are used to retrieve data from tables. The most common DQL statement is SELECT. Here's how you can select data from a table: