0% found this document useful (0 votes)
8 views15 pages

MySQL Lab Exercises for Class 12-C

Google for food um es it was 8jeg up 3rd um kg es i in ez to is

Uploaded by

bhavyarohilacool
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views15 pages

MySQL Lab Exercises for Class 12-C

Google for food um es it was 8jeg up 3rd um kg es i in ez to is

Uploaded by

bhavyarohilacool
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

MySQL Lab

Work 2024-25
Name: Bhavya Rohila
Class: 12-C
Roll No: 27

Question 1)
create table graduate
( sno int(2) primary key,
name varchar(20) not null,
stipend int(3) not null,
subject varchar(20) not null,
average int(2) not null, divi
varchar(2) not null
);

insert into graduate


values(1,'KARAN',400,'PHYSICS',68,'I');
insert into graduate
values(2,'DIWAKAR',450,'COMP Sc.',68,'I');
insert into graduate
values(3,'DIVYA',300,'CHEMISTRY',62,'I');
insert into graduate
values (4,'REKHA',350,'PHYSICS',63,'I');
insert into graduate
values (5,'ARJUN',500,'MATHS',70,'I');
insert into graduate
values (6,'SABINA',400,'CHEMISTRY',55,'I');
insert into graduate
values (7,'JOHN',230,'PHYSICS',64,'II');
insert into graduate
values (8,'ROBERT',450,'MATHS',68,'I');
insert into graduate
values (9,'RUBINA',500,'CHEMISTRY',62,'I');
insert into graduate

values (10,'VIKAS',400,'MATHS',57,'II');

Answer(a)

Answer(b)

Answer(c)
e(i)

e(ii)

e(iii)
e(iv)

(f) create table guide


(
mainarea char(10) references graduate(subject),
advisor char(20) not null
);
insert into guide
values('PHYSICS','VINOD');
insert into guide
values('[Link]','ALOK');
insert into guide
values('CHEMISTRY','RAJAN');
insert into guide
values('MATHS','MAHESH');
select * from guide;

(g)
Question 2)
create table sports
(
studentno int(2) primary key,
class int(2) not null,
name varchar(15) not null,
game1 varchar(20) not null,
grade1 char(1)
check(grade1 in('A','B','C')),
game2 varchar(20) not null,
grade2 char (1)
check(grade2 in('A','B','C'))
);
insert into sports
values(10,7,'SAMMER','CRICKET','B','SWIMMING','A');
insert into sports
values(11,8,'SUJIT','TENNIS','A','SKATING','C');
insert into sports
values(12,7,'KAMAL','SWIMMING','B','FOOTBALL','B');
insert into sports
values(13,7,'VENNA','TENNIS','C','TENNIS','A');
insert into sports
values(14,9,'ARCHANA','BASKETBALL','A','CRICKET','A');
insert into sports
values(15,10,'ARPIT','CRICKET','A','ATHLETICS','C');
select * from sports;
(a)

(b)
(c)

(d)

(e)

(f )
(g)

Question 3)
create table employees
(
empid int(3) primary key,
firstname varchar(10) not null,
lastname varchar(10) not null,
address char(20) not null,
city varchar(20) not null
);
insert into employees
values(010, 'RAVI','KUMAR','RAJ NAGAR','GZB');
insert into employees
values(105, 'HARRY','WALTOR','GANDHI NAGAR','GZB');
insert into employees
values(152, 'SAM','TONES','33 ELM ST.','PARIS');
insert into employees
values(215, 'SARAH','ACKERMAN','440 U.S. 110','UPTON');
insert into employees
values(244, 'MANILA','SENGUPTA','24 FRIENDS STREET','NEW DELHI ');
insert into employees
values(300, 'ROBERT','SAMUEL','9 FIFTH CROSS','WASHINGTON');
insert into employees
values(335, 'RITU','TONDON','SHASTRI NAGAR','GZB');
insert into employees values(400, 'RACHEL','LEE','121 HARRISON ST.','NEW YORK');
insert into employees values(441, 'PETER','THOMPSON','11 RED ROAD','PARIS');

create table empsalary


(
empid int(3) references sports(empid),
salary int(7) not null,
benefits int(7) not null,
designation varchar(15) not null
);
insert into empsalary values(010,75000,15000,'MANAGER');
insert into empsalary values(105,65000,15000,'MANAGER');
insert into empsalary values(152,80000,25000,'DIRECTOR');
insert into empsalary values(215,75000,12500,'MANAGER');
insert into empsalary values(244,50000,12000,'CLERK');
insert into empsalary values(300,45000,10000,'CLERK');
insert into empsalary values(335,40000,10000,'CLERK');
insert into empsalary values(400,32000,7500,'SALESMAN');
insert into empsalary values(441,28000,7500,'SALESMAN')
Employee

EmpSalary
(i) Select Firstname, Lastname, Address, City from Employees where city=”Paris”;
(ii) Select * from Employees order by Firstname desc;
(iii) Select Firstname, Lastname, salary+benefits ”Total Salary” from Employees, EmpSalary
where
[Link]=[Link];
(iv) Select max(salary) from EmpSalary where Designation=”Manager” and Designation=”Clerk”;
Question 4)

i)Select Book_name from Books where author_name=”P. Purohit” and Publishers=”FIRST PUBL.”;

ii)Select Price from BOOKS where Publishers=’FIRST PUBL.’

iii)update BOOKS set


Price=Price-(Price*0.05)
where Publishers="EPB";
iv)select Book_name,Price from BOOKS,issued where BOOKS.book_id=ISSUED.Book_ID and
issued.Qty_Issued>3;

v)select type,sum(price*qty)'total price' from books


group by type;

vi)select * from BOOKS where Price=(select max(Price) from BOOKS)

Q5

create table PRODUCT


(
PCODE varchar(4) primary key,
PNAME varchar(10) not null,
COMPANY varchar(10) not null,
PRICE int(5) not null,
STOCK int(3) not null,
MANUFACTURE varchar(20) not null,
WARRANTY int(1) not null
);
insert into PRODUCT
values("P001","TV","BPL",10000,200,"12-JAN-2008",3);
insert into PRODUCT
values("P002","TV","SONY",12000,150,"23-MAR-2007",4);
insert into PRODUCT
values("P003","PC","LENOVO",39000,100,"09-APR-2008",2);
insert into PRODUCT
values("P004","PC","COMPAQ",38000,120,"20-JUN-2009",2); insert
into PRODUCT
values("P005","HANDYCAM","SONY",18000,250,"23-MAR-2007",3);
select * from PRODUCT;

(a)select * from PRODUCT where PNAME="PC" and STOCK>110;

(b)select COMPANY from PRODUCT where WARRANTY>2


group by COMPANY;

(c)select sum(PRICE*STOCK)'stock value' from PRODUCT

(d)select COMPANY,count(PNAME) from PRODUCT group by COMPANY;


(e) (f)

(g)
(i)

(g)(ii)

Question 6)

create table faculty


(
fid int(3) primary key,
fname varchar(15) not null,
lname varchar(15) not null,
hiredate date not null,
salary int(7) not null
);
insert into faculty values(102,'AMIT','MISHRA','1998-
10-12',12000); insert into faculty
values(103,'NITIN','VYAS','1994-12-24',8000);
insert into faculty
values(104,'RAKSHIT','SONI','2001-05-18',14000);
insert into faculty
values(105,'RASHMI','MALHOTRA','2004-09-11',11000);
insert into faculty
values(106,'SULEKHA','SRIVASTAVA','2006-06-05',10000);

create table courses


(
cid char(3) primary key, fid
int(3) references faculty(fid),
cname char(35) not null, fees
int(7) not null
);
insert into courses values('C21',102,'GRID COMPUTING',40000);
insert into courses values('C22',106,'SYSTEM DESIGN',16000); insert
into courses values('C23',104,'COMPUTER SECURITY',8000); insert
into courses values('C24',106,'HUMAN BIOLOGY',15000); insert into
courses values('C25',102,'COMPUTER NETWORK',20000); insert into
courses values('C26',105,'VISUAL BASIC',6000);

(i)select * from faculty where salary>12000;

(ii)select * from courses where fees between 15000 and 50000;

(iii)select 500+fees'fees' from courses where cname='SYSTEM DESIGN';


(iv)select * from courses,faculty
where [Link]=[Link]
and [Link]=106 order by
cname desc;

(v)select count(distinct fid) from courses;

(vi)select min(salary) from faculty,courses where [Link]=[Link];

(vii)select max(hiredate),min(hiredate) from faculty;

(viii)select fid,sum(fees) from courses group by fid having sum(fees)>20000;

Common questions

Powered by AI

SQL commands ensure accurate data modification and retrieval through precise operations and conditions applied to data sets. Insertions ('insert into graduate values(1,...') add data with adherence to defined table constraints, preserving integrity. SELECT queries with WHERE clauses ('Select Firstname, Lastname from Employees where city="Paris"') retrieve specific data based on conditions, ensuring precision. UPDATE commands modify data with exact criterion matches to maintain consistency, as in updating book prices. Furthermore, JOIN operations illustrated by combining 'courses' and 'faculty' for detailed results merge and align related data constructively, facilitating deeper insights without redundancy .

SQL's grouping function plays a crucial role in data analysis and reporting by aggregating data based on specific field values. In the document, queries such as 'select COMPANY,count(PNAME) from PRODUCT group by COMPANY' reveal insights into product distribution across companies. Similarly, 'select type,sum(price*qty)'total price' from books group by type' provides consolidated financial information. These groupings allow for summarization of large data sets, facilitating reporting and trend discovery. Group functions integrate seamlessly into workflows to produce targeted, high-level data analytics that support decision-making .

Primary keys ensure that each row in a table is unique, as seen in tables like 'graduate', 'employees', and 'sports', which prevents data duplication and maintains integrity. Foreign key references, such as in the 'guide' table referencing 'graduate(subject)' and 'empsalary' referencing 'sports(empid)', ensure that relationships between tables are consistent and that data isn't orphaned. They uphold referential integrity by ensuring that entries in one table match entries in the related table, preventing deletion of referenced records and thus maintaining a consistent database state .

VARCHAR is beneficial when storing variable-length strings, as it conserves space by only using the necessary amount of storage—as can be seen in fields like 'name' and 'subject' in the 'graduate' table. CHAR is suitable for fixed-length fields like 'mainarea' in 'guide' where uniform data size is anticipated. However, VARCHAR may result in slower updates since the variable length can lead to fragmentation. Conversely, CHAR might lead to wasted space if data doesn't utilize its full defined length. Choosing between these types involves balancing storage efficiency and performance considerations based on data variability and query patterns .

CHECK constraints help maintain data quality by enforcing rules at the data entry level—such as ensuring acceptable grades (A, B, C) in the 'sports' table's 'grade1' and 'grade2'. This prevents the insertion of invalid or incorrect data, maintaining standardization across entries. The constraint ensures that any data that does not comply with these rules is rejected, which upholds data integrity and prevents the introduction of errors or irregularities into the database. While effective at ensuring compliance to specific data standards, CHECK constraints also require more careful design and awareness of all permutations should these need updating or extending .

Relational database architecture facilitates complex relationships through table normalization and the use of keys. Each table represents a distinct entity, like 'graduate', 'guide', or 'employees', with relationships established via foreign keys. For example, 'guide' references 'graduate(subject)' to link advisors with students in corresponding subjects, demonstrating a one-to-many relationship feature of relational models. This enables consistency in data handling and ensures that related data is easily queried together, as shown in queries that combine 'faculty' and 'courses' tables to extract teaching information based on faculty IDs, facilitating complex multi-table data analyses .

Foreign keys help achieve higher levels of database normalization by linking tables, reducing redundancy, and separating data into related entities. For example, in the 'guide' table referencing 'graduate(subject)' and 'courses' referencing 'faculty(fid)', foreign keys ensure each subject or course links exactly to one instance of related data. Rather than store repeated advisor or faculty info across subjects, this relational approach minimizes redundancy. While foreign keys enforce data consistency and reduce duplication, they can complicate database schema with growing interconnected tables, making the data architecture hard to navigate if not well-documented .

Category-specific tables such as 'sports' allow for detailed storage and retrieval of information specific to a particular domain or aspect, facilitating focused data management. Summary queries, such as calculating the 'total salary' for employees, synthesize information from different related tables ('Employees' and 'EmpSalary' in this case) to provide aggregated data overviews. These queries enable efficient data analysis by reducing complexity and providing insights derived from multiple data points across tables .

Indexing drastically improves query performance by reducing the amount of data scanned to locate the required information. In queries like finding all employees in Paris or sorting names, indexing relevant columns such as city or lastname can significantly speed up search and sort operations. However, pitfalls include increased storage requirements and slower write operations (such as inserts and updates) since the indexes themselves need to be updated. In the provided schema, careful consideration must be given to balance between read query optimization through indexing and potential overhead during record modifications .

Efficient data queries are supported by the use of primary keys, which naturally index each table on its primary column. This allows for rapid data retrieval based on unique identifiers. For example, selecting employees residing in 'Paris' using 'Select Firstname, Lastname, Address, City from Employees where city="Paris"' takes advantage of potential indexing on frequently queried columns like city, thereby minimizing search time. Structured queries such as selecting maximum salaries ('select max(salary) from EmpSalary') directly extract and compute necessary information due to the organized schema layout, facilitating efficient data processing and retrieval .

You might also like