0% found this document useful (0 votes)
6 views10 pages

DBMS Unit 2.2 by Isometric.

The document outlines various Data Definition Language (DDL) tasks related to different systems, including a Flight Reservation System, Library Management System, Police Department, Weather Monitoring System, and Employee Management System. Each section specifies requirements for creating or altering database tables, including constraints and data types for various columns. The tasks include creating tables, adding columns, truncating data, and dropping tables to maintain data integrity and functionality.

Uploaded by

mahammadnihal12
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)
6 views10 pages

DBMS Unit 2.2 by Isometric.

The document outlines various Data Definition Language (DDL) tasks related to different systems, including a Flight Reservation System, Library Management System, Police Department, Weather Monitoring System, and Employee Management System. Each section specifies requirements for creating or altering database tables, including constraints and data types for various columns. The tasks include creating tables, adding columns, truncating data, and dropping tables to maintain data integrity and functionality.

Uploaded by

mahammadnihal12
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/ 10

0 SUBMIT

(© • Home Learn Any whe re•


user.sq!
t-p rirn ary key ,
erv ati ons • (fli ght _no -in
cre ate• • tab le., flig ht_ res in- var cha r(S O), des tin ati o~
2.2.1. DDL - Flight Reservati
on System SO )•n ot• nul l,•o rig
pas sen ger _na rne ,va rch ar(
ds to store essential flight and var cha r(S O), cla ss- var cha
r(S O)) ;
rvation system. The system nee
You are working on a flight rese are tasked with creating a table to
record
agement and bookings. You
passenger details for flight man information like flight num ber, 2
mation. The table should track
flight details and passenger infor 3
inc lud e•a •ne w-c olu rnn
on, and the class of service. -- Alt er the tab le to-, no var cha r(lO );
passenger name, origin, destinati 4
res erv at-i ons •ad d-c olu rnn -se at_
then truncate 5 alt er tab le flig ht_
column for seat_number, and
table by adding an additional
You will also need to alter the I 6
·- 'Ins erte val lies ;:to ·tal5iJ.! ass eng er_ Ila.TCle,~_•_origin,
all data when needed. 7
yat ion s
8 v IN SE RT ~T O• flig ~re ser
Schema:
flight_reservations Table
9 iVAL UES
Constraints Description
Column Name Data Type 10
A unique identifier for 11

I flight_no INT PRIMARY KEY each flight.

The name of the

I
12
13
14 -- Tru nca te all dat a
from the tab le
res erv ati ons ;

I NOT NULL passenger. tru nca te tab le flig ht_


VARCHAR(50) 15
passenger_name
16

I origin VARCHAR(50)
The origin city of the
flight.
I 17

I destination VARCHAR(50)
,
The destination city of
the flight.
I
I
The class of service
(e.g., Economy,
dass VARCHAR(50)
Business, First Class}.

r.:.E--"ervation Sys tem Req


uirements:
above schema
on details as mentioned in the
St,.,1J 1 • .·r;ci ,e a table for storiog flight reservati
4

. [email protected] • Support logo ut C♦

0 SUBMIT
@ • Home Learn Anywhere•
... e index.sq!
~ ::::::
0
---A dd-t he•e mai l•co lum n
2.2.2. DDL -ALTER • Library System
Management t 1
alte r-ta ble- libr ary_ mem bers •add
•co~ umn •em ail•v arch ar(l OO) ;
to contact library 41 2
nt System and need to add functionality
You are enhancing a Library Manageme emb ers table by adding a new
must update the library_m
members via email. To achieve this, you help the library
the email addresses of members and will
column named email. This column will store ns.
book due dates, events, and notificatio
staff communicate with members about

Requirements:
• The column name should be ema il.
AR(l00).
• The column data type should beVARCH
column can store up to 100 characters.
• Ensure the ss initially.
s, as not all members may have an email addre
• The column should allow NULL value

requirement.
Write an SOL statement to implement this

table, The table is already available in the database.


Note: You are not required to create the

Data Type Constr aints


Column Name
Data Type Constraints
COlunwiName

booklD INT PRIMARY KEY


bool<ID INT PRIMARY KEY

VARCHAR(SO) NOT NULL


firstNam e
firstNvne VARCHAR(SO) NOT NULL

VARCHAR(SOI NOT NULL


lastNam e
lastName VARCHAR(SO) NOT NULL

DATE
.
JOlnDate DATE . JoinDa te

returnD ate DATE


.
DATE
.
returnDate

DECIM AL(l0,2 )
.
. fare
we DECIMALU0,2)

email VARCHAR(lOO)
.
po • logout(♦
• Support
[email protected] ...
.,'·'.•-,~-- -
•· ',:.t,e<

0 SUBMIT
(@ • Home Learn Anywhere•
e index.sq!
~ I

lnfonnation Management Syst


em 0 fro m• the •ta ble
2.2.3. DDL - Police Department .n" 1 ---R em ove •al l•re cor ds•
pol ice _of fic ers ;
ork tru nca te• tab le•
t System. Due to a sudden netw ~ 2
Department's Data Managemen
You are working for the Police internal reco rds, and sen sitive 3
gained to the police department's
breach, unauthorized access was the pol ice _of fic ers table mus t be
ised. As a result, all the data in
officer information was comprom e structure mus t rem ain intact so that
further misuse. However, the tabl
removed immediately to prevent bee n reso lved .
rted after the security breach has
new and verified data can be inse

Task: table as quickly as possible, but


rds from the pol ice _of fic ers
Your task is to remove all the reco
for future secure data entry.
keep the table structure intact

ers:
Table Schema for poli ce_ offic

Data Type Con stra ints

INT PRIM AR" KEY


officerlD

I.■firs,:-Jarnc:

c;il\J ne
VARCHAR(50)

VARCHAR(50)
NOT NUL L

NOT NULL

■ a: I< VARCHAR(50)

I ">..lar DECIMAL(10,2)

I '.Jaltt 11 ••rung DATE

Data Sna psh ot:

firs• Name lastNaMe rank salary dateOfJoinmq


.:if'1cer D
DI Terminal Ee Test case s

ilI~~f'._
~.
_.,. .
• ,,.,.,. ...- ~ · --~t:"'l'.".":i,~ . ,,"'::'~
..... .-:,:·"··::"!, 0 SUBMIT
.-~ . ...'!!'fit .... ' •
~ i lndex.sql --~-:..=----..,,--------------.. •. . :':- ··•,t-' ,. ·.-;a,
(oo46)rfllO@@ c:=t .2
:l! ---T.ype-conten t•nere. • •
2.2.4. DDl: -Weather Monttoi'lng ~stem
. ~
I. • ;,.. '-<' . 1
@I 2 aroP.•ta};>le•WE ;~ttier_oata;
.You are working on a Weather Monitoring System thai collects real-time •weather data from various •••i
. .......... . . . •\!iii···• •• ••
.
regions. Recently, the system underwent a major QVerhaul, a~q all.data _from the old we~tper~data.
table has been success~lly mig[clt9;!_to a new stru~ture. As part o! th_,_ cleanup pr~ce~s~.t~t 9utda~e~ •
weather_d.ata table must be C9mpletely rem9ved from.me database tQ avoid an~ conflicts with the:i
new design. ·>1·
f~..::,
,, -:,\1: '•,' .,'.{!.~: ,_. • ·.•-~~~...

Requirements: -· '.t,i, i".1~:·,:··· ••·;~:,. • :;


;. • The table name is weather~~a~~\t!• ~ •• ···t· ~!!.i",.
i:. . Ensu!'8 th_e table is drppped from the d~t~b~~.\!-;i!h~u!. errors.
·t
~Write an 89L statement to drop the weather_data table fro~ the dalabase. • 'l
Expected Output: . ·,}q •• • ,
:J
The weather-'-da~a.table will be permanently remov~d
. •":·. ~. . . ' - ~-
.·.·,~
,.,,,.
..' • •
·:••:,·
. . .• •
from the database.
••, , • • • . , •... ', "<
~f
'4
l
~ote: You are not required to create the table, The table is already available in the database.
.. ' "- , . •. ' • •• . . • .· . ,.: ~~;:.

. . . --........ '
.. : '.'\ '., ' ,:fr/:

C: -s- lfil Q) :

.,
I..
,
-A

[email protected] ... Support


[_Logout(+ J

Learn Any whe re• 0 SUBMIT


~ A Home
~ 5 index.sq!
key ,.fi rstN am e-
0 ---
(em plo yee ID• int •pr ima ry•
2.2.5. DDL • Employee Managem
ent System
in cre ate -ta ble •er npl oye es• t•n ull ,•b irth Da te• dat e,.
1 tNa me •va r~h ar( 50) •no
its operations. var cha r(5 0)• not •nu ll,• las y> =O ));
eTantra, which is exp and ing cim al( l0, 2), che ck• (sa lar
growing company called Cod hir eD ate -da te,- sal ary •de
You are working for a rapidly ment system to mai ntai n deta iled reco rds of
a robust employee manage
The HR department requires tion , inclu ding thei r pers ona l details,
es. This syst em mus t stor e essential employee informa
all employe nam ed
you need to crea te a tabl e
and hire date s. To ens ure accurate record-keeping,
salaries,
the schema provided below.
emp loy ees that adheres to

:
emp loy ees table schema
Con stra ints
Data Type
C umn Name

PRltvlAHY K'-'l
INT
e ::>loyeelD

NOT NULL
r.rstName VARCl-!AR(50)

I\JuT NULL
•. s:Na me VARCHAR(50)

b ,t1Date DATE

reO e DATE

CHE CK sal, ry >= 0)


~r/

Requirements:
loyees.
• The table name must be emp loyee.
uniquely identify each emp
elD colu mn will serve as the primary key to nam e is
• The employe g that eve ry emp loye e's
Nam e and last Nam e colu mns cannot be null, ensurin
• The first
recorded. ry valu es
ure only non-negative sala
de a check constraint to ens
• The salary column must inclu
are allowed.

___ --
---•·-r_
0 SUBMIT
@ • Home Learn Anywhere•
~ 5
0

2.2.6. DDL -Adding New


Column in 1
Recently, the company ~ 2
ma nagem ent sys tem for a large corporation.
ployee s belong to this new
You are working on an em To track which employee
3
ced a new dep artm ent called "Innovation''. g em plo yee s table by adding
a
introdu d to modify the existin
er dep artm ent, you nee
department or any oth
art me nt.
new column named dep

Requirements: abase.
already exists in the dat
• The employees table to the table.
ed departme nt
• Add a new column nam data type VARCHAR(100).
uld hav e the
column department sho
• The each employee.
the department name for be assigned to a
• This column will store as not all employees may
column can acc ept NULL values initially,
• The
of addition.
department at the time

a:
employees table schem
C0nstrai ,ts
Oat:- "Type
ColLlmn r,.;ame
Pl~lr AR f Ki:-y
::-ployeelD • INT

11rstl',ame
VAR( ,~ 50 NO... '\IULL

,. m'"' t\JULL
VAR< \ '?I 0)
.c:_ • 1ame

tin Or:1te
r r,,..

.,.,r D;it e DATE

CHECI" 5al2 y >= 0)


:i.:, ii'~ DECIMAl(10,2}
- -- -~

Support l!>goutC♦ I
0 0 SUBMIT .. ,
@ • Home learn Anywhere•

ns in SQ L. 2
Gm ,A ·* ~ <P ~. I ~ s index.sq!
... .Q - · · - - - -
- •
~
n•C o} ~
•.

2.2.7. Modifying lhble Stru


ctures and Data: Alteratio 3' 1 • --• Ad d•t he •de sig na tio
information. Per form 2 rch ar( lO O) ;
ed emp in the database,
whi ch stor es em plo yee @I
lum n•d esi gn ati on •va
You are wor king with a tab le nam 3 alt er• tab le• ern p•a dd -co
required:
ate the table structure as
the following tasks to upd 4
pe• of• sal ary
5 --• Ch ang e•t he• Da ta• Ty loa t;
r•c o um n•s ala ry• typ e•f
em p Table Sch em a (Be
fore Modification): alt er• tab le- ern p•a lte
Constraints
Datu l'vpe

PRIMARY KEY
IN •
JeelD

m ;oyee~c1me

OEC"I 1/1 t1 ?

VARCI-< ~, "'O

umn
Tasks 1: Add a New Col
table.
mn nam ed designation to the em p
Add a new colu
tion
• Column Name: designa
100)
• Data Type: VARCHAR( the em p table.
be successfully add ed to
new column designation will
Expected Outcome: The

a Type of salary
Task 2: Change the Dat IMAL(10, 2) to FLOATS.
the salary column from DEC
Change the data type of
• Column Name: salary
• New Data Type: FLOAT8 ATS, allowing it to
mn will be updated to FLO
d Out com e: The dat a type of the salary colu
Exp ecte
store floating-point values.

s will look like:


The emp table schema
after the given modification
0 SUBMIT

a
-

,,
'$,.t"

•• ,:,I . . . ;,,·
."
... • - - , -.. - · · · - · · · - · ···- ,I , ~ "" . •
ue lO ii Uldll~a 111 UIV ~ , ... ,..... , ~1

rmanently delete the table alor:,g with all the data it holds.

Instructions:
• The employees table already exists in the database

se•
• Your task is to completely remove this table from the databa
delete the table and all of its data, so it cannot be recovered unless

• This action will permanently ., ..,,r
.."!/. .•
a backup is available.

the· database.
Write an SQL statement to drop the employees table from

Expected Outcome: .
• The employees table will be successfully removed
from the database•
• All data within the table will be permanently deleted and cannot be recovered unless a backup is

available.
le in the database.
: You ar~,no uired
.
to create the table, The table• is already availab
,.

-
,;'I,;·
•' ..

,.~

I-
1-; -

:·,,::,;. ~
1r.
••

LoqoutC♦~
-• w• ~-~.~:

: '• • , r • •

• Support
;ft!:~\ • .. ·• ..... ..... ....,,,.;J
I


• , ..,~..
~ ~ '

,'ff ~
,•
'
•~:•l

~-:~.>~ I ,•.
'
' ,
0 SUBMIT
re•
) • Home learn Anywhe
~ el index.sq! . j -- _, ' . .

ds• fro m• the •.e n:i p!o Y.e e~ •.ta ble


9. DOL • TRUNCATE -1
in
0
1 --• Re mo ve• all •re cor
artment has
. The company's HR dep 4J 2 ye es;
se adm inistrat or at a rapidly growing tech startup a res truc turing 3 tru nc ate -ta ble -em plo
u are a databa le. However, due to
ining detailed em plo yee data in the em plo yee s tab tab le's structure
en mainta records from the table.
The
team nee ds to tem porarily remove all the plete.
hase, the HR r the restructuring is com
records can be added afte
ust remain intact so that new
out affecting any future
dlin e and nee ds this task to be completed with
he HR team has a tight dea ding and payroll systems.
on the tab le structure, such as employee onboar
perations that depend

Requirements: structu re
table, but keep the table's
jec tive : Remove all records from the employees
• Ob
ints) intact.
(columns, schema, constra re must remain unchanged
le must be clea red of data, but the column structu
• Outcome: The tab
rted in the future.
so that new data can be inse

ema:
em plo yee s table Sch
r.o st air, ts
Data l'Jpe
Colllmn Ha ...
Pnr 1a Vey
. INT
poyc"'ID
NO i NUL L
VARCt iAR (50
, ·IN.-. -t- /

NO T l'lUL L
Vt>QG L\R(50)
.:e.,NJme

U/1 E
',tr\1 1-ar t.

f)"'r F
tureOa'E:

DEC ll\11),L(1' L CHECK (scalarv ·= 0)


-:.~-a'J
12404116.st®IP-u.in • SUP.P-Qit

0 SUBMIT
11
~
.... __1,:f__,£~__
e user.sq!
~Cr eate ;. the • st~~~ t • ~ao
0. DDL-1
base
i~ 11.-
~ v Cre ate •tab le•s. tud ent {'
,..,
re D

tasked with preparing the data ,-


prestigious university, you are ~b atc h- no• int, ••
the database administrator at a orm ance acro ss vario us batc hes, and 3
y nee ds to track student perf I'"
e•v arc har (15 ),
the new semester. The universit ding thei r batch number, nam
e, f"' 4 ~n am
iled infor mation about each student, inclu ~b ran ch• var cha r (15) ,,
system must store deta .f' 5 , '-!'

nch, and marks in three subjects


. 11'·6 ~m ark l•i nt, •
fi"'7,, •••m ark 2•in t
e registrar needs to:
details, including batch number,
name, branch, and mar ks for ,
~.av
• Create a tabl e to store student ,r:,9""'.
·
the first two subjects. l110""' --•A dd• the• mar k3• colu mn- ff
iculum now requires tracking wn n•m arK 3•in e;
s in ·the third subject, as the curr Hf • •stu den t•~ dd• c9l
• Add a new colu mn for mark alte r•ta ble
ent.
marks for three subjects per stud the new batch of students. ..fr
ting data in the table before entering fresh records for ,rj
• Clea r any exis
l,· ~--
.. 14
with the following columns:
ask 1: Create the student table 15
• batch_no (type: INT) 16
• name (type: VARCHAR(15)) 17
• branch (type: VARCHAR(15)) 18
• mark1 (type: INT) 19 ••••
ta
• mark2 (type: INT) 20 ~-• Rem ove •all •ex is_t ing •da
tru nca te-t abl e-s tud ent ;
subject. 21
to store the marks of the third
new column mark3 (type: INT)
Task 2: Alter the.table to add a 22
the table is ready to store fresh
ve all existing data, ensuring that
Task 3: Truncate the table to remo
records for the new batch.

Column Des crip tion :

Column Name
t •r l '• I "I r 11 11, Vitt (
I• I
!11 l 'f I

You might also like