Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Project File

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

1. Create one table using design view and another using sql command.

CREATE TABLE Trains (


Train_No int,
Train_Name varchar(255),
Route varchar(255)
);

CREATE TABLE Passenger (


Pass_Id int,
Train_No varchar(255),
Journey_Date varchar(255),
);

2. Give Primary Key to the Suitable Field in both tables.

CREATE TABLE Trains (


Train_No int,
Train_Name varchar(255),
Route varchar(255)
PRIMARY KEY (Train_No)
);

CREATE TABLE Passenger (


Pass_Id int,
Train_No varchar(255),
Journey_Date varchar(255),
PRIMARY KEY (Pass_Id)
);
3. Insert 3 records using datasheet view in one table and 3 records using sql
command in another table.

--Insert values to Train table


INSERT INTO Trains VALUES (1234, 'Duranto Express', 'Mumbai');
INSERT INTO Trains VALUES (2368, 'Sabarmati Express', 'Delhi');
INSERT INTO Trains VALUES (3689, 'Rajdhani Express', 'Banglore');

-- fetch some values


SELECT * FROM Trains WHERE Route = 'Mumbai';
SELECT * FROM Trains WHERE Route = 'Delhi';
SELECT * FROM Trains WHERE Route = 'Banglore';

Insert values to Passenger table


-- insert some values
INSERT INTO Passenger VALUES (1, '1234', '18/01/2023');
INSERT INTO Passenger VALUES (2, '2368', '19/01/2023');
INSERT INTO Passenger VALUES (3, '3689', '20/01/2023');

-- fetch some values


SELECT * FROM Passenger WHERE Journey_Date = '18/01/2023';
SELECT * FROM Passenger WHERE Journey_Date = '19/01/2023';
SELECT * FROM Passenger WHERE Journey_Date = '20/01/2023';
4. Create relationship between tables.
SELECT Trains.Train_No, Passenger.Pass_Id, Trains.Route
FROM Trains
INNER JOIN Passenger ON Trains.Train_No=Passenger.Pass_Id;

Pass_Id Train_No Train_Name Journey_Date Route


1 1234 Duranto Express 18/01/2023 Mumbai
2 2368 Sabarmati Express 19/01/2023 Delhi
3 3689 Rajdhani Express 20/01/2023 Banglore

SQL COMMANDS for the following :-

1. Update any one record in the table using any condition.

UPDATE Trains
SET Train_Name = 'Pune Express', Route= 'Pune'
WHERE Train_No = 4568;

Train_No Train_Name Route


1234 Duranto Express Mumbai
2368 Sabarmati Express Delhi
3689 Rajdhani Express Banglore
4568 Pune Express Pune

2. Delete any one record from the table using any condition.

DELETE FROM Trains WHERE Train_No=1234;

3. Alter the structure of the table.

ALTER TABLE Passenger


ADD Route varchar(255);
4. Display all the records of both the tables in ascending or descending
order of using any one field.

Pass_Id Train_No Train_Name Journey_Date Route


1 1234 Duranto Express 18/01/2023 Mumbai
2 2368 Sabarmati Express 19/01/2023 Delhi
3 3689 Rajdhani Express 20/01/2023 Banglore

You might also like