elASSMATe
Date
Page
SQL- DATABASE.
PART-2
Nhat is the SELECT statement?
A SELECI command aets zexo 0Y more xowsS
fxom one ox more databa.se tables oz views
The most freguent data Manipulation langugge
OML command is SELECT in_most applications.4
SELECTqueries define a yesult set but not ho Fo
calculate it, becquse SOL is a declayative
pyoqygmming 1anguage
What Qxe some common clause used with
SELECT Queyuin SQL
The follotoing axe Some frequent SCL clauses used
inconiuction with a SELECT Gueyy
WHERE clause i In SOL, the WHERE clause is
used to filter yecoxds hat aye xequixed
dependino on ceytain _cxiteyiq
ORDER BY clauseThe ORDER BY clause in SQL
isused to Sovt da ta in ascending ASC) oY
descending DESC) ordey dependinq on specific
fteld()(DEsC). eTUL KUmaRLINKEDIN)
NOTES qmLLERy CTELEqRANM),
OROUP By clauSe CROUP BY clause in SQL is used
to ayoup entxies with identical data and may be
used l t h aggreqation methods to obtaîn
Summaise.d datgbgse Yesults
Continue
ATUL UmRunKEDI), 14
clASSMALe
Date
Page
HAVING clause_i- The HAVING clause in SQL 1s used
to fltey yecoxds in_combination uith the GRODP 15y_
clauseIt is different fYom WHERE since the nlHERE
Clause cannot filtey aa qreqate d yec0 Yds
3 Does SQL Suppo7t pyoayamminea lanauage
Featuyes?_
SSL efers to th e Standard uery Lanquage
Iherefoxe,it is true that SQL i a language hut-
does not actually support the proqxamm ing
lanqua ge It is 9 common language that doesn't a
lo.Dp Conditiona statements, and 10gical Opexations
It cannot be used roY anuthing Other than data
manipulation It is a command language to pexfoxm
database opeyations. he pximary puypose of SaL.
is 4o xetrieye, maniputete, update, delete, and
pex Poxm_complex operations liKejoins on the dara
present in fhe database.
ATUL 4Umar lLNKEDIN),.
NOTES GALLERY (TELEQRAM)|
4 Ahat are_Constraints in SOL?
ConstyQints are used to specify the ules
Concexning data in the table If can be applted
for single or Multiple fieldsin an SQL tQble
during the creation of the table or Qftey
Creating usinq the ALTER TABLE Command
he consraintS are
NOT NOLL Restxic.ts NULL value from being
fnsested into column
ATUL Um LiNIKEDIN)
Continue
elASSMAte
Date
Page
CHECK- Vavifies that au values In a field Satisfy
a Condition
DEPAULT Automatically assigns default value
Ifno value has been specified for the field
UNIQUEEnsues unigue values fo be inserted
into the field
TNDEX-Indexes a field providing faster fetrieva|
ofxecOYds. ATuL AumaR uNKEDin).
NOTES qmiGRY TELERM).
PRIMARY KEY Uniquely identifies each recoids in
a table.
FOREIGN KEY Ensuyes xe fesential integsity for a
ecoid in another table
5 What axe the Subsets of SOL
he foll0wing are the fouy sianiftcant subsets
Of the SQL
Data de finition anguage (DDL)-It define.s the
data tyuctuye that Consists Of commands like
CREATEALTER DROP etc.
Data Manipulatfon langugge(DML It is used to
Manipulate existinq data in database. The comman d3s
n thls categ ozu axe SELECT OPDATE, INSERT erc
Continue
ATuL KUmR (LINKEDIn) 3
clASSMALte
Date
Page
Data Conttrol LanQuage DCL)-1E ContYols accesS
fo the data stOsed o the database The commands
i othis categosy include GRANT and REVOKE.
xan saction Control Langugge TCL) Tt is used to
deal nlth the tyansaction_operarlons in the dafabase.
he commands In this CategOXy Qre COMML ROLLBACK
SET TRANSACTION, SAVE POTNT ete
6 Alhat aye UNION MINUS and INTERSECT comman ds
The ONIoN Ope1atoy is used to combine the results
of tw0 table5 hile also emoving duplicate entsies
TheMENUS opexator Is used to 1etuin YOWS from
the elrst Query but not from the second ueYy
The NTERSECT operator is used to combine the
results Of both queries into a Singie yOwis.
Before 1unning elther of the above SOL SBatements
Certain yequl1ements must be sqtisfied
Ithinthe clause each SELECT qUeyy must have
the sa me amount of Columns
The data types in the columns mus also be
CompaYable. ATutkum RLINKEDIN)
NOTES GALLERY CTELERAM),
In egch SELECT Statement the columnS must
be in the same ordey.
ATUL maRLLINKEDIN)
elAsSMALe
Date
( Page
hat Is a Primary keu
h e PRIMARY KEY constralnt uniquely identifles eqch
YON in a tablel t must contatn UNIQUE Values
and ha.s gn implicit NOT NULL Constyaint. A table
in saLis stxictly yestyicted to have one and only
one primary Key, which is comprised of single
OY multiple felds Ccolumns)
CREATE TABLE Students Create table vwith a
Singie Aetd as_primary keu
IDINT NOT NULL
Name VARCHAR (255)
PRIMARY KEy (ID ATuL kwmR UNKEDI)
lOTES qALLERy CTELEURAM).
CREATE TABLE Students C/* Create table i t h
multiple flelds as
primayu key
ID INT NOT NOLL
Lastnlame VARCHAR (255)
FirstName VARCHAR (255) NOT NULL
CONSTRAJNT PK-Student
PRIMARy KEY (ID Firstaame)
ALTER TA BLE Stud ents/* Set a column as primavy
key
ADDPRIMARY KEy (ID);
ALTER TABLE SFudents Set multlpte columns as
primary Key
ATUL HUmk LnKEDIn) Continue 5
alasSMAte
Date
Page
ADDCONSTRAINT PKStudent/Alaming o Primaryy
Key
PRIMARYy KEy (ID, FiystnName)_
Ialrite a Sql statement to add the primary key
t-id to the table teqcheys'
Nxite SQL tatement to gdd the pyimayy Key
constyaint pk-a foy table 'table-a and fleids
col-b col-C'
Ahat iS the purpose of DDL Langugge
DDL Stands fox Data Definition Language I is
the subset of g datobgse that defines the data
stucture of the databa.se uhen the database 1s
CYeated Fox exgmpie, We can use the DDL Command
to add xemove OY modify tables.It consists of the
followinq commands: CREATE ALTER and DELETE
database objects such qs schema, tables, indexes,
view sequence erc
Example
ATUL 4umaR (LNKEDIn)
NOTES cULERY(TELEURAM),|
CREATE TABLG Students
Roll-no LNT
Name vARCHAR (45)
Branch VARCHAR (30),
TUL mt(LnKEpIN)