Apurva Ag. Dbms
Apurva Ag. Dbms
EXPERIMENT 1
1. COMPANY DATABASE:
EXPERIMENT 2
INSERTING
INSERT INTO `college`.`student` (`stu_id`, `stu_name`, `stu_ph_no`, `stu_dob`) VALUES
('911', 'Apurva Agarwal', '7012253752', '2005-03-20');
INSERT INTO `college`.`student` (`stu_id`, `stu_name`, `stu_ph_no`, `stu_dob`) VALUES ('912',
'Prachi Negi', '8549976278', '2005-01-10');
INSERT INTO `college`.`student` (`stu_id`, `stu_name`, `stu_ph_no`, `stu_dob`) VALUES ('913',
'Vinay Singh', '9972548677', '2004-05-10');
INSERT INTO `college`.`student` (`stu_id`, `stu_name`, `stu_ph_no`, `stu_dob`) VALUES ('914',
'Shreya Kumari', '8754987217', '2004-05-07');
INSERT INTO `college`.`student` (`stu_id`, `stu_name`, `stu_ph_no`, `stu_dob`) VALUES ('915',
' Priyanshu Yadav', '7842187549', '2005-04-20');
INSERT INTO `college`.`student` (`stu_id`, `stu_name`, `stu_ph_no`, `stu_dob`) VALUES ('916',
'Shruti Agarwal', '8754861747', '2004-10-12');
Apurva Agarwal 22SCSE1012878 Section26
UPDATING
UPDATE student
WHERE stu_id='915';
UPDATE branch
SET brn_name=’Statistics’
WHERE brn_id=’1002’;
DELETING
DELETE FROM student
WHERE stu_id='914';
Apurva Agarwal 22SCSE1012878 Section26
EXPERIMENT 3
3.PERFORM THE FOLLOWING:
a) Altering a Table, Dropping/Truncating/Renaming Tables,
Altering a Table:
ALTER TABLE Course
ADD COLUMN semester VARCHAR(20);
Dropping a Table:
DROP TABLE Student;
Truncating a Table:
TRUNCATE TABLE STUDENT;
Renaming a Table:
ALTER TABLE branch
RENAME TO branches;
b) Adding a column
ALTER TABLE student
ADD COLUMN year_of_study INT;
EXPERIMENT 4
1. CREATE TABLE Student (Roll int PRIMARY KEY, Name varchar(25) , Course varc
har(10) );
Here column Roll is acting as Primary Key, which will help in deriving the value of
foreign key in the child table.
2. CREATE TABLE Subject (Roll int references Student, SubCode int, SubName va
rchar(10) );
In the above table, column Roll is acting as Foreign Key, whose values are derived using the
Roll value of Primary key from Master table.
Apurva Agarwal 22SCSE1012878 Section26
EXPERIMENT 5
5. FOR A GIVEN SET OF RELATION SCHEMES, CREATE TABLES AND PERFORM THE
FOLLOWING AGGREGATE FUNCTIONS (MAX/MIN/SUM/AVG/COUNT).
The following SQL statement finds the sum of the "unit price" fields in
the "products" table:
Apurva Agarwal 22SCSE1012878 Section26
The above code will give us the minimum quantity in stock in the
products table.
The code depicted below will give us the maximum quantity in stock in
the products table.
EXPERIMENT 6
ID Name Salary
1 Rohan 57000
2 Aryan 45000
3 Arpit 60000
4 Harsh 50000
5 Tara 55000
SELECT * FROM teaches;
Output :
course_id prof_id course_name
1 1 English
1 3 Physics
2 4 Chemistry
2 5 Mathematics
Output
Using the Inner Join we are able to combine the information in the two tables
based on a condition and the tuples in the Cartesian product of the two tables
that do not satisfy the required condition are not included in the resulting
table.
course_id prof_id Name Salary
1 1 Rohan 57000
Apurva Agarwal 22SCSE1012878 Section26
1 3 Arpit 60000
2 4 Harsh 50000
2 5 Tara 55000
Inserting Data:
EXPERIMENT 7
CREATE TABLE:
Age int(2),
Phone int(10)
);
-- Insert some sample data into the Customers table
INSERT INTO Customer (CustomerID, CustomerName, LastName, Country,
Age, Phone)
VALUES (1, 'Shubham', 'Thakur', 'India','23','xxxxxxxxxx'),
(2, 'Aman ', 'Chopra', 'Australia','21','xxxxxxxxxx'),
(3, 'Naveen', 'Tulasi', 'Sri lanka','24','xxxxxxxxxx'),
(4, 'Aditya', 'Arpan', 'Austria','21','xxxxxxxxxx'),
(5, 'Nishant. Salchichas S.A.', 'Jain',
'Spain','22','xxxxxxxxxx');
Output:
Query:
SELECT Department, sum(Salary) as Salary
FROM employee
GROUP BY department
HAVING SUM(Salary) >= 50000;
Apurva Agarwal 22SCSE1012878 Section26
Output:
DISTINCT Clause:
Query
CREATE TABLE students (
ROLL_NO INT,
NAME VARCHAR(50),
ADDRESS VARCHAR(100),
PHONE VARCHAR(20),
AGE INT
);
Inserting some random data to perform distinct operations.
Apurva Agarwal 22SCSE1012878 Section26
Query:
SELECT DISTINCT NAME FROM Student;
Output:
LIMIT Clause:
Student Table:
CREATE TABLE student (
id INT PRIMARY KEY,
name VARCHAR(50),
age INT
);
Queries:
SELECT *
FROM student
LIMIT 3;
Output: