Dbms Q
Dbms Q
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> -- Create Passengers Table
mysql> CREATE TABLE Passengers (
-> PassengerID INT PRIMARY KEY,
-> Name VARCHAR(50),
-> FlightID INT,
-> SeatNumber VARCHAR(5),
-> FOREIGN KEY (FlightID) REFERENCES Flights(FlightID)
-> );
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> -- Create Airlines Table
mysql> CREATE TABLE Airlines (
-> AirlineID INT PRIMARY KEY,
-> Name VARCHAR(50),
-> Country VARCHAR(50)
-> );
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> -- Create Aircraft Table
mysql> CREATE TABLE Aircraft (
-> AircraftID INT PRIMARY KEY,
-> Model VARCHAR(50),
-> Capacity INT,
-> AirlineID INT,
-> FOREIGN KEY (AirlineID) REFERENCES Airlines(AirlineID)
-> );
Query OK, 0 rows affected (0.01 sec)
mysql> -- Insert data into Airlines Table
mysql> INSERT INTO Airlines (AirlineID, Name, Country) VALUES
-> (1, 'Delta Airlines', 'USA'),
-> (2, 'Southwest Airlines', 'USA');
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql>
mysql> -- Insert data into Aircraft Table
mysql> INSERT INTO Aircraft (AircraftID, Model, Capacity, AirlineID) VALUES
-> (1, 'Boeing 737', 180, 1),
-> (2, 'Airbus A320', 160, 2);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql>
mysql> -- Insert data into Flights Table
mysql> INSERT INTO Flights (FlightID, FlightNumber, DepartureCity, ArrivalCity,
DepartureTime, ArrivalTime) VALUES
-> (1, 'AA101', 'New York', 'Los Angeles', '2024-11-27 08:00:00', '2024-11-27
11:30:00'),
-> (2, 'DL202', 'New York', 'Atlanta', '2024-11-27 09:00:00', '2024-11-27
12:00:00'),
-> (3, 'SW303', 'Chicago', 'Dallas', '2024-11-27 14:00:00', '2024-11-27
16:30:00');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql>
mysql> -- Insert data into Passengers Table
mysql> INSERT INTO Passengers (PassengerID, Name, FlightID, SeatNumber) VALUES
-> (1, 'John Doe', 1, '12A'),
-> (2, 'Jane Smith', 1, '12B'),
-> (3, 'Alice Johnson', 2, '15C');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> SELECT *
-> FROM Flights
-> WHERE DepartureCity = 'New York';
+----------+--------------+---------------+-------------+---------------------
+---------------------+
| FlightID | FlightNumber | DepartureCity | ArrivalCity | DepartureTime |
ArrivalTime |
+----------+--------------+---------------+-------------+---------------------
+---------------------+
| 1 | AA101 | New York | Los Angeles | 2024-11-27 08:00:00 |
2024-11-27 11:30:00 |
| 2 | DL202 | New York | Atlanta | 2024-11-27 09:00:00 |
2024-11-27 12:00:00 |
+----------+--------------+---------------+-------------+---------------------
+---------------------+
2 rows in set (0.00 sec)
mysql>
mysql> -- Add the foreign key constraint
mysql> ALTER TABLE Flights ADD CONSTRAINT fk_aircraft FOREIGN KEY (AircraftID)
REFERENCES Aircraft(AircraftID);
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> -- Update the Flights table to associate flights with specific aircraft
mysql> UPDATE Flights SET AircraftID = 1 WHERE FlightID = 1; -- Delta Airlines
flight
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql>
mysql> -- Create Scholarships Table
mysql> CREATE TABLE Scholarships (
-> ScholarshipID INT PRIMARY KEY,
-> StudentID INT,
-> Amount DECIMAL(10, 2),
-> FOREIGN KEY (StudentID) REFERENCES Students(StudentID)
-> );
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> -- Insert data into Scholarships Table
mysql> -- (Test inserting valid and invalid cases later)
mysql> DELIMITER $$
mysql>
mysql> CREATE TRIGGER ValidateGPA
-> BEFORE INSERT ON Scholarships
-> FOR EACH ROW
-> BEGIN
-> DECLARE gpa DECIMAL(3, 2);
->
-> -- Retrieve the GPA of the student
-> SELECT GPA INTO gpa FROM Students WHERE StudentID = NEW.StudentID;
->
-> -- Check if GPA is below 3.0
-> IF gpa < 3.0 THEN
-> SIGNAL SQLSTATE '45000'
-> SET MESSAGE_TEXT = 'Student GPA must be 3.0 or higher to receive a
scholarship.';
-> END IF;
-> END$$
Query OK, 0 rows affected (0.02 sec)
mysql>
mysql> DELIMITER ;
mysql> INSERT INTO Scholarships (ScholarshipID, StudentID, Amount)
-> VALUES (1, 1, 1000.00); -- John Doe has a GPA of 3.50 (Valid)
Query OK, 1 row affected (0.01 sec)
mysql>
mysql> -- Insert Data
mysql> INSERT INTO Gym VALUES
-> (121, 'Vanshaj', 'Saharanagar', '[email protected]', 11223365564, 5),
-> (122, 'SlimGYM', 'Asaranagar', '[email protected]', 65165125, 8),
-> (123, 'NationalGYM', 'Madinachawk', '[email protected]', 6223355, 4);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql>
mysql> -- Insert Data
mysql> INSERT INTO Student VALUES
-> (71, 'Aman Shaikh', 22113344, 19, 1),
-> (72, 'Safwan Shaikh', 55447788, 19, 1),
-> (73, 'Naveed Shaikh', 33665544, 21, 2),
-> (74, 'Saad Inamdar', 88779911, 20, 3);
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql>
mysql> -- Insert Data
mysql> INSERT INTO Package VALUES
-> (1, 'Gold', 3, 4000),
-> (2, 'Silver', 6, 8000),
-> (3, 'Platinum', 12, 12000);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> SELECT
-> Student.stu_id,
-> Student.stu_name,
-> Student.stu_contact,
-> Student.stu_age,
-> Package.P_name,
-> Package.P_duration,
-> Package.p_amount
-> FROM
-> Student
-> JOIN
-> Package
-> ON
-> Student.P_id = Package.P_id;
+--------+---------------+-------------+---------+----------+------------
+----------+
| stu_id | stu_name | stu_contact | stu_age | P_name | P_duration | p_amount
|
+--------+---------------+-------------+---------+----------+------------
+----------+
| 71 | Aman Shaikh | 22113344 | 19 | Gold | 3 | 4000
|
| 72 | Safwan Shaikh | 55447788 | 19 | Gold | 3 | 4000
|
| 73 | Naveed Shaikh | 33665544 | 21 | Silver | 6 | 8000
|
| 74 | Saad Inamdar | 88779911 | 20 | Platinum | 12 | 12000
|
+--------+---------------+-------------+---------+----------+------------
+----------+
4 rows in set (0.00 sec)
mysql>
mysql> -- Insert Data
mysql> INSERT INTO SupplierTable VALUES
-> (1, 'FreshFruits', 'California', 1223456789),
-> (2, 'TropicalTreats', 'Hawaii', 7894561230),
-> (3, 'OrganicOrchards', 'Solapur', 7894566123),
-> (4, 'JuicyJungle', 'Mumbai', 4567891238),
-> (5, 'FarmFresh', 'Pune', 5234567893);
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> select *
-> from fruit
-> where Ripe_date>12/2/2024;
+-------------+------------+--------+--------+-------+------------+
| Supplier_id | Fruit_name | color | Taste | price | Ripe_date |
+-------------+------------+--------+--------+-------+------------+
| 1 | mango | Yellow | Sweet | 50 | 2024-12-04 |
| 2 | grapes | Green | Sweet | 40 | 2024-04-12 |
| 3 | apple | Red | Sweet | 40 | 2024-04-25 |
| 4 | maxi | Khaki | Bitter | 30 | 2024-04-18 |
| 5 | marlin | Maroon | Bitter | 15 | 2024-05-19 |
+-------------+------------+--------+--------+-------+------------+
5 rows in set (0.00 sec)
mysql>