0% found this document useful (0 votes)
12 views11 pages

DBMS Mod2

The document provides an introduction to SQL, detailing its role as a structured query language for interacting with databases. It covers various SQL commands categorized into sublanguages such as DDL, DML, and DQL, explaining their functions like creating, altering, and querying database structures. Additionally, it includes examples of SQL commands for manipulating data and managing database objects.

Uploaded by

aleenadarvin
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)
12 views11 pages

DBMS Mod2

The document provides an introduction to SQL, detailing its role as a structured query language for interacting with databases. It covers various SQL commands categorized into sublanguages such as DDL, DML, and DQL, explaining their functions like creating, altering, and querying database structures. Additionally, it includes examples of SQL commands for manipulating data and managing database objects.

Uploaded by

aleenadarvin
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/ 11

Intnodu ctton to SQh.

SQL ’ stnuctued @uery kanguage


’1s a standasd phogna mmong kamgea,.
Ied to (nteact wcth dalabases
pri mari y used to
he sthuctve of a dalabue
I. Defene
2- Manipulate dala tnsent, updala,
olelete
3. uey the database to ae tsieere
tafor mation
SaL io categoniged nto diseent
sublanguages
Create, tte , Dogp,
Tinca! I DDL (eata Referituon kamguag
DMA (Oafa Mani pulaton Lamguag)
Insert updali, Delet Slet2-
Grant, Ravoke 3- Dek (Data Controt hamguge
Gelect 4. DQL (Bala Quy Lamguage)
Commit,Ro tlback, 5. TeL (hansacton Coniot Lamgu
Release soeponl.
tDDL (Rata Refeiton Language)
modfie s the st uctue of
Defnes like tables, indezes
data base
and schemas At
Commands used n DDL
CRE ATE to creale a databa8e o4 lable

ALTER ’ îo modisy an exs tong table 'a's


structue
DROP- olatabase
o elelete databse objects.
TRUNCATE -’ Go deelo
ll hOws from
et
cwrtho Log gng nd1vided
ta ble
ow dele at on.

kg lCreali dala base


dalabase name employedad
CREATe dalabase
IlCreale table
Employees (empid int paimany,
CREATE TABLE Decimalio, 2),
Salany
Name varchar(20),
Depant ment varchar(30);
column
cw
ew to the table
/ Add a
DD Email varchan
TABLE Employees A Croo);
ALTER
Beleli toble.
DROP T ABLE Employees

lary Departrrant
Name Sa
Pmpid
Aten AHter
Department mail
empid Name Salany
op aa. Colen
PROP cOAUMN Email
ALTE R TABAE Employees
/Touncala
TRUNCATe ABLE Ernployees
ROP VS RUN CA TE
Oyeence blw
Thuncale
Jnop thu lablo
-eleted. he table| Gheseued
the ocUS e
Gable Cnly
nolong earote henoved
Shuclui

de let Atl 00s ae Aemoed,


&ala All dala i
wcth te stnuctwe semanig
along
3lowen thau Jaslir, as it bypasses
ow deled ong
TRUNCA TE . loggng
Commands used u pMA
manipulales olala sloruel
-’ Manages and
n dlatabase objec ts
Commends
new Houus
owS
INSERT > to add
exsting dala
UPDATE ’’ tomodig
hemove ows o dala
DELE Te >To dalã ((somécmes connidered
SELECI > Ret ueees But ofen rd en DML)
part os pes
INSERT

INSERT INTO Employees


Values (io Alice,
1500 O.o0 CsE):
csE3
Values (to'John',
Employees
tNsERT INTO
o0, T'):
values (103 Hari
INTOE mployees
(NSeRT
81000 o0,'eCe')!
Seportment
empid Name salany
T5000.0d
CSe
Alce
John B4000. DO
31000. o eCE
Hari

=89000Do
SeT Galany
UPDATE Employees
WHERE emped = |01j
102
F2bM enployees where empcd =
DELeTE
SELECT Com mand.

refhieue daã nom tabl


’ used to
students
SELECT # fROm
Students
Co wrse fROM
SELECT mame,

sELECT *FRom stud ts cohere age 7a:

: + unêvenscty ibnary cwants to


books and
maui tai a dala base of
Studente. o
Cuali tatles Books, students,
Books (book id, title ,authoh, publuhed gea,
avaitabt _copus)
Students (stud-id, mame,49e co wse, email)

coum
O Mo dlitg table
tàble dd a
Gere to Books table
()Retreve the lest o all books auail able
kibnang
(8) Fund all stude nfs coho au
second gBudyng
(4) Relete the,stadet named Ahee
Snop the sBudenl tabll comp tely
Petala table Books( bo ok-id int pemary kay
title vaschar (too) nof nutl autho varcharleo)
not mull, publishd-year int, auailable- topi
cnt);
students (stud-id int prinasy keuy
Creali ta ble CHEckO
mame vancharlso) not null, age
between 18 and
tnt
tnt(age
30), cou Se varchanlso)
email vas char(coo) un ique);
ADD gerne vardhar(50).
( Alter table Books
Q.select * foom Books
whoe conse
foom students
3.Select *
ten Sci ence':
Compu ohre na =Ale.
=
foom s tudent
4. Delete
Table students;
6. Doop
Uaivesity Gustous (a"Hodule)
eiveely dißseneut steps
ottt au eaample,
1.sllusthals aneR diaqmam urto
synthesi g ng(1)
nvolved o
ulateoual gchema
E abot domau
CoMsthacnt cess
2 Ds consthacnts and
2. tohat s
Constaaent, entety eomitna ut weth
ouetablk
rejseutal teqiilg
etample (1)
tepes awailable to
h. hist the baste data
wi sAL (5)
defening att cbutes
DROP & DELETE
Dlorntali blu) ( 6)
5- ALTER & UPDATE.
INSE RT
3
Gglustnale an9
Staliment wi saL. (6)
based on t
sAL DDL stali ments
7jUHilE bchema (A sS ume
dala base
followtng
buttable domau types )
signatton, Salaay,compid)
Employee (eid , name ,de addss, twnover)
ompang (Comp-id , ernam. ,
omenttone d tables asumu
above
6)Creal the employees: Menteoi
eompany has many
éach ound mot nal
the paimany key, foreign keg
consthacnts
both tha tables. Memttou
) Srsert vaues (nto will be
onder nsesttons
lv which
Caned out
) Modity the ta ble Employee to ene lude a
ew column "yeans-o- ep
henement the salag ot employees whose
) by 5%
salary s less than Rs 25000 (8)
8. Convent the kollo awng ER diagham entoe
se lattonal schema
useaname
(Subnitdate dala

studente Scabmi
SSLan aSsigu,
mnt

9. what s foruignkuy constnacin t 2 wky ae


such constnants mportant ?
o cohaf u Rujenenteal Enteqity
follocon elatou schama wit
I1. Considen the
nujenenti al Sntegity conatnacrts
yeas sex,duptNio, adyisoA )
g+uDENTollno ,mame, daqre
PARTMENS deptld, name, hod, phone)
DE
SSORempl,name, Sex, Staat Yeay deptne phone
PROFE
statement for the follo ng
wAla SaL PDL PROPeSSOR
STUD eNT, De PHRTmENT,
table
I: Crea
paimang and foreign kay cntegoiy
ncludn table stud en t
Constoants bute cn the
add vess atti
2 Add am statement to delete the
3.wait an saL ntgnug
pastment Gtven the <ntal
"cs" de cohen -tfes
Const naut eaplaci cchat happens
Statement o ezeauted.
CREATE TABLE PEPARTMET

deptid Alumbe Poi ma oy key,


na me varcha (50) unl'que,
hod numbey)
phome vavchar (5),
Constrant fkhod FOREIGNEKEY(hod) REFERENE
PROFESSOR (e mp) ON DELE TE SET NUL

CREATE TABLE PROfessO R

empld numbes
name varchar (50)
Paimay Key
Sex varchar (2),
Startyear Numbe,
deptNo Num be
phone varchar (15
FoREIGN key (dept No)
Constraent fkpopdel
RGFERENCES DE PARTMeNT( dept+4) ON DELETE O
CREATe TABLe STUDENT
goll no Numbe Ponimary key.
name varcha

degee archar,
yea Numbe,
Sex char
dept nNo Number,
aducson
Nlumbe
address Uaschas (a0),
stud_depta foRero NkEY (daptNo)
constrant fk. oN DELETe CASCADe,
DEPARTmENI(deptld )
RereRENCES
foRe GN key (advsor
Constvacnt fk-stud ad ves07 oN PeLe 7E SEs
PROfessoR (empld)
Re FeReNces

tabe steudenl
attibute en
addess chcur(20e).
an vas
. Add address
student ADD
table
Alter tment
cs depas
te
fe
3-Rele the mame : C5
ENT
DEPARTmENS ohere
pelete from
foor
Ohat happers when gou dulele Bepasliat
S+UDENT
STvDENT ah
ahd PROFESS OR
m
vn
() he deptNo (n DEPARTmEN7 weth
ajerences deptzD
DELEiE CAS CA DE
ON

e delete the cs Aepartmenf, all


when ce
pratessors belongng to that
Shsdenlã and
depardmant outll be auto mattaly delt.
(2) he hod uin Repartment seferences
empld co PROFe SS OR wetfh ON DEAE TE SEf Nu
CS
cs Bepantment ezut
’1 the HOD o the
DEPARIMeNg otll be set to ULL
deleted.

ON DELE TE CASCADE IS Used , dleleteng a

Pa cohd å panent ta ble wÁll automaticaly


delete all elated Hecords u the chi td taBle

You might also like