We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 10
MySQL
Create a Database named INSTITUTE.
> create database INSTITUTE;
Query OK, 1 row affected (0.02 sec)
Create a table named FACULTY with the
following structure.
ATTRIBUTE DATATYPE CONSTRAINT
FID Integer PRIMARY KEY
Fname Text data with max length 25 characters NOT NULL
Lname Text data with max length 25 characters NOT NULL
and UNIQUE
HIRE_DATE DATE
SALARY DECIMAL SIZE 7,2 Must be >= 5000
> create table FACULTY(F_ID int primary key,
Fname varchar(25) not null, Lname varchar (25)
unique not null, HIRE_DATE date, SALARY
decimal(7,2) check (SALARY >= 5000));
Query OK, 0 rows affected (0.08 sec)Create a table named COURSES
ATTRIBUTE DATATYPE CONSTRAINT
CID Text(10) PRIMARY KEY.
FID Integer Foreign Key
CNAME TEXT SIZE 40 CHARS_| DEFAULT VALUE “BASIC COURSE”
FEES DECIMAL SIZE 7,2
with the following structure.
> create table COURSES(C_ID char (10)primary
key, F_ID int, CNAME varchar (40)default "BASIC
COURSE", FEES decimal(7,2),foreign key(F_ID)
references FACULTY (F_ID));
Query OK, 0 rows affected (0.11 sec)
Insert following data records into FACULTY
table and COURSES table.
FACULTY
FID | Fname Lname Hire date ry
102 Amit Mishra 10-1998 12000
103 Nitin Vyas 1994 8000
104) Rakshit Soni 18-5-2001 14000
105 Rashmi, Mathowa 1-9-2004 11000
Sulekha sta 5-6-2006 10000)
Niranjan’ 6-8-1996. 16000
Fees,
0000
System Design 16000
C23 O04 Computer Security 8000
24_| 106 Human Biology 15000
25 | 102 ‘Computer Newwork [20000
C26 103 Visual Basic 6000,
C27 07 Dreamweaver 4000> insert into FACULTY value (102, "Amit",
"Mishra", "1998-10-12",12000);
> insert into FACULTY value (103, "Nitin",
"Vyas", "1994-12-24", 8000);
> insert into FACULTY value (104, "Rakshit",
"soni™,"2001-5-18",14000);
> insert into FACULTY value (105, "Rashmi",
"Malhotra","2004-9-11",11000);
> insert into FACULTY value (106, "Sulekha",
"Srivastava", "2006-6-5",10000);
> insert into FACULTY value (107, "Niranjan",
"Kumar", "1996-8-26",16000);
Table — COURSES
> insert into COURSES value ('C21', 102, 'Grid
Computing', 40000);
> insert into COURSES value ('C22', 106,
"System Design',16000);
> insert into COURSES value ('C23', 104,
"Computer Security',8000);
> insert into COURSES value ('C24', 106, 'Human
Biology',15000);
> insert into COURSES value ('C25', 102,
"Computer Network', 20000);
> insert into COURSES value ('C26', 105,
"Visual Basic',6000);> insert into COURSES value
"DreamWeaver',
4
("c27', 107,
000);
To display all records from FACULTY table.
> Select * from faculty;
rows in set
(
1998-10-12
1994-12-24
2004-09-11
2006-06-05
| 1996-08-26
-t---
0.00 sec)
To display all records from COURSES table.
> Select * from
4+------ +------ +
| C_ID | F_ID |
4$--=--- hose
| c2l | 102 |
| c22 | 106 |
| c23. | 104 |
| c24 | 106 |
| c25 | 102 |
| c26 | 105 |
| c27 | 107 |
4+------ $------ +
7 rows in set (
courses;
------------------- $o---------4+
CNAME | FEES
------------------- 4+----------+
Grid Computing | 40000
System Design | 16000
Computer Security | 8000
Human Biology | 15000
Computer Network | 20000
Visual Basic | 6000
DreamWeaver | 4000
------------------- $----------+
0.00 sec)To display all records from FACULTY table whose
Hire date is more than 05-oct-2001.
> select * from FACULTY where hire date >'2001-
10-05';
+
2 rows in set (0.02 sec)
To display F_ID, Fname, Cname of those
faculties who charged more than 15000 as fees.
> select F_ID, Fname, Cname from FACULTY
natural join COURSES where FEES > 15000;
| 102 | Amit | Grid Computing |
| 106 | Sulekha | System Design |
| 102 | Amit | Computer Network |
to----- tannnnnn-- tenon non-H nH n= +
3 rows in set (0.01 sec)Display count of all records from COURSES table
grouped by F_ID.
> select F_ID, count(*) from COURSES group by
°
ny
+o Het
5 rows in set (0.02 sec)
Display all records FACULTY table order by
First Name of the faculty in descending order.
> select * from FACULTY order by Fname desc;
-+
|
+
! 6 | | Srivastava
| 105 | Rashmi | Malhotra
| 104 | Rakshit | Soni
| 103 | Nitin | vyas
\ | | Kumar
\ 2 | | Mishra
+
6 rows in set (0.00 sec)
To increase the fees of Dreamweaver course by
500.
> update COURSES set FEES = (FEES + 500) where
Cname = 'Dreamweaver';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0Alter COURSES table to change size of CNAME
field to varchar (50).
> Alter table COURSES modify column Cname
varchar (50);
Query OK, 0 rows affected (0.06 sec)
Records: 0 Duplicates: 0 Warnings: 0
Alter FACULTY table to add a new field to Phone
Number varchar (15) .
> Alter table FACULTY add column ph_no
varchar (15);
Query OK, 0 rows affected (0.09 sec)
Records: 0 Duplicates: 0 Warnings: 0
Display distinct F_ID from COURSES table.
> select distinct (F_ID) from COURSES;
5 rows in set (0.00 sec)Delete records from COURSES table having F_ID
as 102.
> delete from COURSES where F_ID = 102;
Query OK, 2 rows affected (0.02 sec)
Display records from FACULTY table where Last
name starts with ‘M’.
> select * from FACULTY where Lname
a oe fannnnnnnan to —=
| FID | Fname | Lname lt
aneee desea
| 105 | Rashmi | Malhotra | 2004-09-11 | 11000.00
| 102 | Amit | Mishra | 1998-10-12 | 12000.00 |
a4
2 rows in set (0.01 sec)
SALARY
Display today’s date.
> select curdate();
$------------ +
| curdate() |
$o------------ +
| 2022-08-28 |
4+------------ +
1 row in set (0.01 sec)Display Faculty names from FACULTY table who
handle/teach more than one Course.
> select Fname, Lname from faculty natural join
courses group by courses.f id having count(*) >
| Sulekha | Srivastava |
+- ----+ --
1 row in set (0.01 sec)
Display all records from FACULTY table whose
phone number is NULL.
> select * from FACULTY where ph_no is
_
HIRE_DATE
| SALARY
NULL
+
| 102 | Amit ' 1998-10-12 | 12000.00 |
| 103 | Nitin Hl 1994-12-24 | 8000.00 |
| 104 | Rakshit | 2001-05-18 | 14000.00 | '
| 105 | Rashmi | 2004-09-11 | 11000.00 I
| 106 | Sulekha | 2006-06-05 | 10000.00 | NULL |
| 107 | Niranjan | 996-08-26 | 16000.00 | I
aeShow the structure of FACULTY table and COURSES
table.
> desc COURSES;
Default | Extra |
H a
| C_ID | char (10) | No PRI | NULL = | |
| FID | int | YES | MUL | NULL | |
| Cname | varchar(50) | YES | NULL | |
| FEES | decimal(7,2) | YES | NOLL | |
+
4 rows in set (0.03 sec)
> desc FACULTY;
Null | Key |
varchar (25)
I I
I |
| Lname | varchar (25) |
| HIRE_DATE | date \ I
Si 5 | decimal (7,2) |
| varchar (15) |
6 rows in set (0.00 sec)
Delete all records from COURSES table.
> delete from courses;
Query OK, 5 rows affected (0.01 sec)
Revoke the last delete operation.
> rollback;
Query OK, 0 rows affected (0.01 sec)
Drop COURSES table.
> drop table courses;
Query OK, 0 rows affected (0.07 sec)