Day01_01_Database+Basics
Transcript of Day01_01_Database+Basics
-
7/24/2019 Day01_01_Database+Basics
1/62
FPT Software 1
Instructor:
DATABASE BASICS
-
7/24/2019 Day01_01_Database+Basics
2/62
FPT Software 2
Agenda
Database Concepts Entity Relationship Modeling MS SQL Server (MSSQL Express
2008 !vervie"
Data #ypes DDL DML
-
7/24/2019 Day01_01_Database+Basics
3/62
FPT Software 3
$ data %odel is a &description' o both acontainer or data and a %ethodology orstoring and retrieving data ro% container)&*o+ can thin, o a data %odel as thein rastr+ct+re o the data organi-ations. in other"ords. the "ay data is presented to the +ser)'Data %odel is
/ot a thing*o+ cannot to+ch itData %odel are abstractions. %athe%atical algorith%s Concepts)
Data Model
-
7/24/2019 Day01_01_Database+Basics
4/62
FPT Software 4
Data base %anage%ent syste%s ollo" partic+lar %odels (,no"n as database %odels to store and%anip+latedata) $ data base %odel is characteri-ed by1
) #he "ay it stores data 1 S#R3C#3RE
2) #he "ay data in the
str+ct+re are %anip+lated1!4ER$#5!/S
Data base %anage%ent syste%s ollo" partic+lar %odels (,no"n as database %odels to store and%anip+latedata) $ data base %odel is characteri-ed by1
) #he "ay it stores data 1 S#R3C#3RE
2) #he "ay data in the
str+ct+re are %anip+lated1!4ER$#5!/S
Database Systems Models
-
7/24/2019 Day01_01_Database+Basics
5/62
FPT Software 5
Evol t!on of Database Model
6
Li%itationsSearching orrecordsData Red+ndancyData 5nconsistency
FLATFILE
Indexed
file 5ndex
#able #able #able
$dvantages
!verca%e li%itations Co%pact Easy to +se $cc+rate
Data in boo,sand registers
Man+al databases
-
7/24/2019 Day01_01_Database+Basics
6/62
FPT Software "
T#e $elat!onal Database
& $ D7MS that %anages data as collection otables in "hich all data relationships arerepresented by co%%on val+es in relatedtables)'
&$ D7MS that ollo"s all the t"elve r+les oC!DD is called RD7MS'
-
7/24/2019 Day01_01_Database+Basics
7/62
FPT Software %
TA&'E Str (t re 1)2
$ttrib+tes
Cardinalit
y
4ri%aryey
#+ples
S+pplier Do%ainDo%ain
SCode SName Quantity City
S1 Kamran 20 Lahore
S2 Zafar 10 I lama!adS" A#mat $0 Kara%hi
S$ A!dul "$ Lahore
S& Na ir 2& I lama!ad
-
7/24/2019 Day01_01_Database+Basics
8/62
FPT Software *
TA&'E Str (t re 2)2
-
7/24/2019 Day01_01_Database+Basics
9/62
FPT Software +
E,- .nstan(e of St dents $elat!on
id Name Lo'in a'e ()A
53666 Jones Jones@ca 18 3.4
53444 smith Smith@ecs 18 3.2
53777 Blake Blake@aa 19 3.8
9 Cardinality : ;. arity : 6 . all ro"s distinct
Do all val+es in each col+%n o a relation instance have to be distinctigh level data %odel that is +se +l indeveloping a concept+al design or a database
E$ D!agram E$D6- !ne o the irst steps in designinga database
E$D Elements 1 Entities Relationships $ttrib+tes
-
7/24/2019 Day01_01_Database+Basics
17/62
FPT Software 1%
Ent!ty $elat!ons#! Model!ngSam le E8$ D!agram
-
7/24/2019 Day01_01_Database+Basics
18/62
FPT Software 1*
Ent!ty $elat!ons#! Model!ng&as!( E8$ 9otat!on
Entitysy%bols
Relationshipsy%bols
$ttrib+tesy%bols
$ specialentity that isalso arelationship
-
7/24/2019 Day01_01_Database+Basics
19/62
FPT Software 1+
Ent!ty $elat!ons#! Model!ngAttr!b tes
$ttrib+te property or characteristic o an entity type Classi ications o attrib+tes1
Si%ple vers+s Co%posite $ttrib+te Single Aal+ed vers+s M+ltival+ed $ttrib+te Stored vers+s Derived $ttrib+tes 5denti ier $ttrib+tes
-
7/24/2019 Day01_01_Database+Basics
20/62
FPT Software 2/
Ent!ty $elat!ons#! Model!ng.dent!f!ers :eys6
5denti ier ( ey $n attrib+te (or co%bination oattrib+tes that +ni?+ely identi ies individ+alinstances o an entity type
Si%ple ey vers+s Co%posite ey
Candidate ey an attrib+te that co+ld be a,eyFsatis ies the re?+ire%ents or being a ,ey Characteristics o 5denti iers1
Gill not change in val+e Gill not be n+ll /o intelligent identi iers (e)g) containing locations or
people that %ight change S+bstit+te ne". si%ple ,eys or long. co%posite ,eys
-
7/24/2019 Day01_01_Database+Basics
21/62
FPT Software 21
Ent!ty $elat!ons#! Model!ngA (om os!te attr!b te
An attr!b te bro;en!nto (om onent arts
-
7/24/2019 Day01_01_Database+Basics
22/62
FPT Software 22
Ent!ty $elat!ons#! Model!ngS!m le ;ey attr!b te
#he ,ey is +nderlined
-
7/24/2019 Day01_01_Database+Basics
23/62
FPT Software 23
Ent!ty $elat!ons#! Model!ng0ard!nal!ty of $elat!ons#! s 1)2
$elat!ons#! s !ne to !ne1 Each entity in the relationship "ill have
exactly one related entity !ne to Many1 $n entity on one side o the relationship
can have %any related entities. b+t an entity on the otherside "ill have a %axi%+% o one related entity
Many to Many1 Entities on both sides o the relationshipcan have %any related entities on the other side
0ard!nal!ty 0onstra!nts the n+%ber o instances o oneentity that can or %+st be associated "ith each instance oanother entity)
Mini%+% Cardinality 5 -ero. then optional 5 one or %ore. then %andatory
Maxi%+% Cardinality1 #he %axi%+% n+%ber
$ l d l
-
7/24/2019 Day01_01_Database+Basics
24/62
FPT Software 24
Ent!ty $elat!ons#! Model!ng0ard!nal!ty of $elat!ons#! s 2)2
-
7/24/2019 Day01_01_Database+Basics
25/62
FPT Software 25
Ent!ty $elat!ons#! Model!ng&!nary relat!ons#! s
-
7/24/2019 Day01_01_Database+Basics
26/62
FPT Software 2"
E$ Model 8 0onvert E$ Modelsto $elat!onal s(#ema D& Des!gn6
R+les or converting ER Model torelational sche%a 7asic Conversion R+les Entity #ype R+le M Relationship R+le
M / Relationship R+le 5denti ication Dependency R+le
-
7/24/2019 Day01_01_Database+Basics
27/62
FPT Software 2%
E$ Model- D& Des!gn$ le 1 8 E,am le
C3S#!MER relation
C3S#!MER entity type "ithsi%ple attrib+tes
7iHn IJi ,iK+ th c thK th ng thNOng
-
7/24/2019 Day01_01_Database+Basics
28/62
FPT Software 2*
M+ltival+ed attrib+te beco%es a
separate relation "ith oreign ,ey
to %any relationship bet"een originalentity and ne" relation
Convert M+ltival+e attrib+te
E$ Model- D& Des!gn$ le 2 8 E,am le
-
7/24/2019 Day01_01_Database+Basics
29/62
FPT Software 2+
E$ Model- D& Des!gn$ le 3 8 E,am le
EM4L!*EE relation "ith rec+rsive oreign
,ey
EM4L!*EE entity "ith Managesrelationship
Convert 3nary relationship one to one
-
7/24/2019 Day01_01_Database+Basics
30/62
FPT Software 3/
E$ Model- D& Des!gn$ le 3 8 E,am le
Convert binary relationship one to one
-
7/24/2019 Day01_01_Database+Basics
31/62
FPT Software 31
E$ Model- D& Des!gn$ le 3 8 E,am le
EM4L!*EE relation "ithrec+rsive oreign ,ey
EM4L!*EE entity "ithManages relationship
Convert 3nary relationship one to %any
-
7/24/2019 Day01_01_Database+Basics
32/62
FPT Software 32
E$ Model- D& Des!gn$ le 3 8 E,am le
/ote the %andatory one
$gain. no n+ll val+e in theoreign ,eyFthis is beca+se
o the %andatory %ini%+%cardinality
Convert 7inary relationship one to %any
-
7/24/2019 Day01_01_Database+Basics
33/62
FPT Software 33
E$ Model- D& Des!gn$ le 3 8 E,am le
7ill o %aterialsrelationships (M1/
5#EM and C!M4!/E/#relations
Convert 3nary relationship %any to %any
-
7/24/2019 Day01_01_Database+Basics
34/62
FPT Software 34
E$ Model- D& Des!gn$ le 3 8 E,am le
/e" intersectionrelation=oreign ,ey
=oreign ,ey
Co%posite pri%ary ,ey
#he Supplies relationship "ill need tobeco%e a separaterelation
Convert 7inary relationship %any to %any
$
-
7/24/2019 Day01_01_Database+Basics
35/62
FPT Software 35
E$ Model- D& Des!gnAnot#er 0onvert!ng E,am le
Convert #ernary relationship
E$ M d l D& D !
-
7/24/2019 Day01_01_Database+Basics
36/62
FPT Software 3"
E$ Model- D& Des!gnAnot#er 0onvert!ng E,am le
Convert #ernary relationship
-
7/24/2019 Day01_01_Database+Basics
37/62
FPT Software 3%
Ms S
-
7/24/2019 Day01_01_Database+Basics
38/62
FPT Software 3*
=#at !s S
-
7/24/2019 Day01_01_Database+Basics
39/62
FPT Software 3+
Ms S
-
7/24/2019 Day01_01_Database+Basics
40/62
FPT Software 4/
Ms S
-
7/24/2019 Day01_01_Database+Basics
41/62
FPT Software 41
Database Eng!ne
Database Engine is the core service or storing.processing. and sec+ring data #his incl+des creating tables or storing data. anddatabase obPects s+ch as indexes. vie"s. and stored
proced+res or vie"ing. %anaging. and sec+ring data
-
7/24/2019 Day01_01_Database+Basics
42/62
FPT Software 42
$e ort!ng Serv!(e
Reporting Services (SSRS incl+des1 $ co%plete set o tools that yo+ can +se to create and %anage
reports. $n application progra%%ing inter ace ($45 that allo"s
developers to integrate or extend data and report processing inc+sto% applications
-
7/24/2019 Day01_01_Database+Basics
43/62
FPT Software 43
$e l!(at!on
Replication is a set o technologies or copying anddistrib+ting data and database obPects ro% onedatabase to another. and then synchroni-ing bet"eendatabases to %aintain consistency
-
7/24/2019 Day01_01_Database+Basics
44/62
FPT Software 44
.ntegrat!on Serv!(es
5ntegration Services (SS5S is a plat or% or b+ilding highper or%ance data integration sol+tions. incl+dingextraction. trans or%ation. and load pac,ages or data"areho+sing
-
7/24/2019 Day01_01_Database+Basics
45/62
FPT Software 45
Ms S
-
7/24/2019 Day01_01_Database+Basics
46/62
FPT Software 4"
S
-
7/24/2019 Day01_01_Database+Basics
47/62
FPT Software 4%
SSMS Demo
De%o
-
7/24/2019 Day01_01_Database+Basics
48/62
FPT Software 4*
S
-
7/24/2019 Day01_01_Database+Basics
49/62
FPT Software 4+
S
-
7/24/2019 Day01_01_Database+Basics
50/62
FPT Software 5/
Ms S
-
7/24/2019 Day01_01_Database+Basics
51/62
FPT Software 51
E,a(t 9 mbers
7igint1 8 7ytes)
Store integer data ro% 2 ; to 2 ; #his is +sed in special case "here the integer val+es exceed the ranges+pported by the int data type)
5nt1 7ytes) Store integer data ro% 2 ; to 2 ; #his can be +sed to store pri%ary ,ey o a table)
S%allint) 2 7ytes) Store integer data ro% 2 6 to 2 6
#inyint1 7yte) Store integer data ro% 0 thro+gh 266 #his can be +sed to store pri%ary ,ey o table as Bender or #itle
Deci%al1 /+%eric data types that have ixed precision and scale /+%eric1 #he sa%e as Deci%al
7it1 #his can ta,e a val+e o . 0. or /3LL) Money1 8 7ytes) #his sho+ld be +sed in special case. in nor%al case "e
sho+ld +se deci%al instead
-
7/24/2019 Day01_01_Database+Basics
52/62
FPT Software 52
E,a(t 9 mbers Demo
De%o
-
7/24/2019 Day01_01_Database+Basics
53/62
FPT Software 53
A ro,!mate 9 mer!(s
=loat Real
-
7/24/2019 Day01_01_Database+Basics
54/62
FPT Software 54
A ro,!mate 9 mer!(s Demo
De%o
-
7/24/2019 Day01_01_Database+Basics
55/62
FPT Software 55
Date and T!me
SQL s+pport belo" Date and #i%e data type1 Date Dateti%eo set Dateti%e2 S%alldateti%e Dateti%e #i%e
-
7/24/2019 Day01_01_Database+Basics
56/62
FPT Software 5"
Date and T!me demo
De%o
-
7/24/2019 Day01_01_Database+Basics
57/62
FPT Software 5%
0#ara(ter Str!ngs
Char(n 1 =ixed length. non 3nicode string data):n :8000
Aarchar(nT%ax 1 Stores non 3nicode string data n de ines the string length and can be a val+e ro%
thro+gh 8.000 %ax indicates that the %axi%+% storage si-e 2B7
/char(n 1 =ixed length. 3nicode string data /varchar(nT%ax 1 Stores 3nicode string data
-
7/24/2019 Day01_01_Database+Basics
58/62
FPT Software 5*
&!nary Str!ngs
7inary Aarbinary 5%age
-
7/24/2019 Day01_01_Database+Basics
59/62
FPT Software 5+
&!nary Str!ngs Demo
De%o
-
7/24/2019 Day01_01_Database+Basics
60/62
FPT Software "/
7t#er Data Ty es
ti%esta%p hierarchyid +ni?+eidenti ier s?lUvariant x%l table
-
7/24/2019 Day01_01_Database+Basics
61/62
FPT Software "1
7t#er Data Ty es Demo
De%o
-
7/24/2019 Day01_01_Database+Basics
62/62