Dbms assignment programs
Dbms assignment programs
Unit -1
*Output:*
2)2)
Create a table and use describe keyword and display the table
Here’s an example of creating a table, using the `DESCRIBE` keyword
to display its structure, and then displaying the table itself:
```
■ Create a table called “employees”
CREATE TABLE employees (
Employee_id INT PRIMARY KEY,
Name VARCHAR(255),
Department VARCHAR(255),
Salary DECIMAL(10, 2)
);
*Output:*
*DESCRIBE employees:*
```
Customer_name VARCHAR(255),
Customer_address VARCHAR(255),
Order_id INT,
Order_date DATE,
Product_name VARCHAR(255),
Quantity INT
);
Customer_name,
Customer_address,
Order_id,
Order_date,
Product_name,
Product_price,
Quantity
VALUES
```
```
Customer_name VARCHAR(255),
Customer_address VARCHAR(255)
);
Customer_id INT,
Order_date DATE,
Product_name VARCHAR(255),
Quantity INT
);
VALUES
(1, ‘John Doe’, ‘123 Main St’),
VALUES
```
Split the `orders` table into two tables: `orders` and `order_items`.
```
Customer_name VARCHAR(255),
Customer_address VARCHAR(255)
);
Customer_id INT,
Order_date DATE
);
Order_id INT,
Product_name VARCHAR(255),
Quantity INT
);
VALUES
VALUES
(1, 1, ‘2022-01-01’),
(2, 2, ‘2022-01-15’);
VALUES
Split the `order_items` table into two tables: `order_items` and `products`.
```
Customer_name VARCHAR(255),
Customer_address VARCHAR(255)
);
Customer_id INT,
Order_date DATE
);
Product_name VARCHAR(255),
Product_price DECIMAL(10, 2)
);
Product_id INT,
Quantity INT
);
VALUES
VALUES
(1, 1, ‘
```)
Create tables
Name VARCHAR(255),
Age INT,
Department VARCHAR(255)
);
CourseName VARCHAR(255),
Credits INT
);
StudentID INT,
CourseID INT,
Grade VARCHAR(255),
);
■ Insert data
VALUES
VALUES
VALUES
SELECT S.*
FROM Students S
SELECT *
FROM Courses
SELECT S.*
FROM Students S
```
These SQL queries achieve the same results as the relational calculus
queries:
*Query 1 Results:*
|-----------|------|-----|------------|
|1 | John | 20 | CS |
|2 | Jane | 21 | EE |
*Query 2 Results:*
| 102 | Algorithms | 4 |
*Query 3 Results:*
|-----------|------|-----|------------|
|1 | John | 20 | CS |
Create tables
Name VARCHAR(255),
Age INT,
Department VARCHAR(255)
);
Name VARCHAR(255),
Age INT
);
■ Insert data
VALUES
VALUES
■ Union Operation
UNION
SELECT Name, Age FROM CS_Students;
INTERSECT
■ Projection Operation
FROM Students;
■ Selection Operation
SELECT *
FROM Students
```
*Output:*
_Union Operation:_
| Name | Age |
| John | 20 |
| Jane | 21 |
| Bob | 22 |
| Alice | 20 |
| Mike | 21 |
| Emma | 22 |
_Intersection Operation:_
| Name | Age |
| John | 20 |
| Alice | 20 |
_Projection Operation:_
| Name | Age |
| John | 20 |
| Jane | 21 |
| Bob | 22 |
| Alice | 20 |
| Mike | 21 |
_Selection Operation:_
|-----------|------|-----|------------|
|3 | Bob | 22 | ME |
*Note:* The INTERSECT operation may not work in all SQL databases (e.g.,
MySQL). Instead, use:
```
FROM Students
FROM CS_Students
Unit -2
-- Create table
city,
24) state,
25) zip_code,
26) country,
27) date_of_birth,
28) last_purchase,
29) total_purchases,
30) is_active
31) )
32) VALUES
33) (1, 'John Doe', 'john.doe@example.com', '1234567890', '123
Main St', 'New York', 'NY', '10001', 'USA', '1990-01-01', '2022-01-01',
100.00, TRUE),
34) (2, 'Jane Doe', 'jane.doe@example.com', '9876543210', '456
Elm St', 'Los Angeles', 'CA', '90001', 'USA', '1995-06-01', '2022-06-01',
200.00, TRUE),
35) (3, 'Bob Smith', 'bob.smith@example.com', '5551234567', '789
Oak St', 'Chicago', 'IL', '60601', 'USA', '1980-03-01', '2022-03-01',
50.00, FALSE);
36)
37) -- Display table
38) SELECT * FROM customers;
39) ```
40)
41) _Output:_
42)
43) | customer_id | name | email | phone | address
| city | state | zip_code | country | date_of_birth | last_purchase |
total_purchases | is_active | created_at |
44) |-------------|------------|------------------------|-------------|-------------|----------
-----|-------|----------|---------|---------------|---------------|------------------|-----------|--
-------------------|
45) |1 | John Doe | john.doe@example.com | 1234567890 |
123 Main St | New York | NY | 10001 | USA | 1990-01-01 |
2022-01-01 | 100.00 | TRUE | 2024-03-01 12:00:00 |
46) |2 | Jane Doe | jane.doe@example.com | 9876543210 |
456 Elm St | Los Angeles | CA | 90001 | USA | 1995-06-01 |
2022-06-01 | 200.00 | TRUE | 2024-03-01 12:00:00 |
47) |3 | Bob Smith | bob.smith@example.com | 5551234567
| 789 Oak St | Chicago | IL | 60601 | USA | 1980-03-01 |
2022-03-01 | 50.00 | FALSE | 2024-03-01 12:00:00 |