0% found this document useful (0 votes)
16 views2 pages

2021ugcs051 Assignment

The document describes creating tables to store student and item records in a database. It includes SQL commands to create the tables, insert sample data, and queries to retrieve specific records. Examples include listing female students, finding the youngest male student, and querying item prices and expired items.

Uploaded by

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

2021ugcs051 Assignment

The document describes creating tables to store student and item records in a database. It includes SQL commands to create the tables, insert sample data, and queries to retrieve specific records. Examples include listing female students, finding the youngest male student, and querying item prices and expired items.

Uploaded by

Abhisar Sahay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment 2

DDL & DML Commands (Basics)


Name-Abhisar Sahay
Reg-2021UGCS051
A. Suppose that a faculty wants to keep records about the students, the
desired records should maintain
this information about each student: (Roll No, Full name, CGPA, Age, and
Gender)
a. Create the appropriate Table.
create table student ( roll int primary key, name varchar(50) not null, cgpa float not null, age int not null, gender
varchar(10) not null );

insert into student values(1,"Dhruv",8.52,20,"male"); insert into


student values(2,"Arpit Rathi",9.2,21,"male"); insert into
student values(3,"Aashish Tyagrajan",6.8,20,"male"); insert
into student values(4,"Aman Mittal",8.17,21,"male"); insert into
student values(5,"Supriya Singh",8.2,19,"female") insert into
student values(6,"Sneha Singh",9,19,"female") insert into
student values(7,"Priya",8.,19,"female")

b. Write SQL Queries to answer the following problems:


-List the names of all female students.
SELECT * from student where gender="female";

-What is the age of the youngest male student?


Select name,age from student where gender like "male" order by age asc limit 1;

- List the name and the CGPA for all students who got above 6.5 CGPA
ordered by their CGPAs then their names.
Select cgpa,name from student where CGPA>6.5 order by CGPA desc;

- What is the Topper name?


Select cgpa,name from student where CGPA>6.5 order by CGPA desc limit 1;
3. A supermarket manager likes to keep records about all the items in his
store these records should hold the following information about each item
(the item identifier item_id, the item name, the item price, expiration date
of the item, quantity in hand)
a. Create the appropriate table.
create table item( id int primary key, name varchar(50) not null, price float not null, exp date, quantity int
not null );

insert into item values(1,"sauce",15.50,2023-05-16,10);


insert into item values(2,"burger",25.50, 2025-05-21,5);
insert into item values(3,"chicken",80, 2026-05-20,8);
insert into item values(4,"mutton",80, 2024-07-17,9) ; insert
into item values(6,"mutton",80, 2023-04-16,1);

b. Write sql queries to answer the following problems:


- List the names and prices for all items that have a quantity in hand >20.
select name,price from item where quantity>20;

- List the names of expired items.


select * from item where exp<curdate();

- name the second most expensive item.


select * from item order by price desc limit 1,1;

-Alter the table structure to make sure that no negative value can be
assigned to the price field
alter table item add check (price>=0);

You might also like