SlideShare a Scribd company logo
1 of 53
Er. Nawaraj Bhandari
Database Design &
Developmentf
Topic 7 & 8:
Physical Design 2
Types of Constraints
 Entity integrity
 Referential integrity
 Propagation constraints
 Domain constraints
 Table constraints
Activity – Recap - 1
 What is the Entity integrity rule?
 What is referential integrity?
Activity – Recap - 2
 What is the Entity integrity rule?
 The primary key of an entity cannot contain nulls.
 What is referential integrity?
 If a foreign key contains a value then that value
must refer to an existing tuple in the source table
The Art Suppliers data model - where will
there need
to be constraints?
Order OrderItem Item
Supplier
1 1
1
0...*
0...* 0...*
Customer
1
0...*
Source or Parent Table
Create table customers
(CustomerNo integer(5) not null,
first_name varchar(30),
last_name varchar(30),
primary key emp_no);
Referencing or Child Table
Create table Orders
(OrderID integer(5) not null,
CustomerID integer(5) not null,
OrderDate datetime,
primary key OrderID,
foreign key (CustomerID) references Customer
(CustomerID);
Referential Integrity Constraint – Another
Example
Create table workers
(emp_no integer(5) not null,
first_name varchar(30),
last_name varchar(30),
job_title varchar(30),
age integer(3),
dept_no integer(5),
primary key emp_no,
foreign key (dept_no) references Departments (dept_no)o)
Propagation Constraint
 What happens if we delete a Item from our Art Supply database?
 There are lots of OrderItem records that reference it. What happens to
them?
Options for Propagation
 No action
 Cascade
 Set Default
 Set Null
Table with Propagation Constraint
with no action and cascade
Create Table Item
(ItemID integer NOT NULL,
SupplierID integer NOT NULL,
Price float,
Primary Key (ItemID),
Foreign Key (SupplierID) REFERENCES Supplier(SupplierID)
On delete no action
On update cascade);
Table with Propagation Constraint
with Set Default
Table with Propagation Constraint
with no action and cascade
Create Table Item
(ItemID integer NOT NULL,
SupplierID integer NOT NULL,
Price float,
Primary Key (ItemID),
Foreign Key (SupplierID) REFERENCES Supplier(SupplierID)
On delete set Null
On update set Null);
Domain Constraints
 Product Type could be enforced as...
 a check constraint
 separate domain using Create Domain statement
 as a foreign key to another table
Check Constraint
Create Table ProductType
(ProductTypeID integer NOT NULL,
ProductTypeName varchar (30) NOT NULL,
ProductTypeColour varchar (20),
Primary Key (ProductTypeID)
Check (ProductTypeColour in ‘Red’,’Blue’,’Green’));
As a Separate Domain
Create Domain ProductTypeColour As varchar(20)
Default ‘Red’
Check (Value in (‘Red’,’Blue’,’Green’));
 The table’ProductType’ will set the
ProductTypeColour attribute as this domain
ProductTypeColour
Create Table ProductType
(ProductTypeID integer NOT NULL,
ProductTypeName varchar (30) NOT NULL,
ProductTypeColour BoatType,
Primary Key (ProductTypeID));
As a Separate Table
Create Table ProductTypeColour(
(ProductTypeColourCode Varchar(3),
ProductTypeColourDescription Varchar(20)
Primary Key (ProductTypeColourCode));
With the corresponding Foreign Key in Boat
Create Table ProductType
(ProductTypeID integer NOT NULL,
ProductTypeName varchar (30) NOT NULL,
ProductTypeColour varchar (3),
Primary Key (ProductTypeID)
Foreign Key (ProductTypeColourCode)
References ProductTypeColour (ProductTypeColourCode));
Business Rules Enforced by Constraints
 Business rules are derived from requirements analysis and
documented in logical design
 They depend on the operations of the ‘real world’ business
Business Rule: No order may contain
more than 10 OrderItems
Order OrderItem Item
Supplier
1 1
1
0...*
0...10 0...*
Customer
1
0...*
Table Constraints
Create Table Orders
(
(OrderID integer NOT NULL,
CustomerID integer NOT NULL,
OrderDate datetime NOT NULL
Constraint MaximumOrderItems
Check(Not Exists(Select OrderID
From OrderItems
Group By OrderID
Having Count(*) >10)),
Primary Key (OrderID)
Foreign Key (CustomerID) REFERENCES Customer(CustomerID)
On delete no action
On update cascade);
Table Constraints – Another Example
Create Table Rental
(
(BoatID integer NOT NULL,
CustomerID integer NOT NULL,
RentalStartDate datetime NOT NULL,
RentalEndDate datetime NOT NULL
Constraint MaximumRentals
Check(Not Exists(Select BoatID
From Rentals
Group By BoatID
Having Count(*) >10)),
Primary Key (BoatID, CustomerID, RentalStartDate)
Foreign Key (CustomerID) REFERENCES Customer(CustomerID),
Foreign Key (BoatID) REFERENCES Boat (BoatID)
On delete no action
On update cascade);
Some Additional Database Structures
 Views
 Indexes
 Sequences
View of
selected rows
or columns of
these tables
Improving Performance with the use of
Views
Table 1
Table 2
Table 3
Query
Example of Creating a View
Create View OrderSummary as
(Select O.OrderID, O.OrderDate, I.ItemName, I.Price, OI.Quantity, O.Total
From Orders O, OrderItems OI, Items I
Where O.OrderID = OrderItems.OrderID
And I.ItemID = OI.ItemID);
 What will be the purpose of this view?
Indexes
 Improve performance.
 They work by creating entries in a special structure that makes it
easier to find a record
Index Types
 Primary index
 Secondary index
 Clustering index
Primary Index
 Built around a key field that is used for ordering. A unique value for
every entry in the index.
Secondary Index
 Defined on a non-ordering field
 May not contain unique values
 Improves the performance of queries that use columns other than
primary key
Use of Secondary Indexes
 Mechanism for specifying additional key columns.
 For example Customer would be searched often on Customer Name as
well as the primary key and so a secondary index could be used on it.
Examples of Creating Indexes in SQL
 To create primary index
 CREATE UNIQUE INDEX CustomerIDIndex
 ON Customer(CustomerID)
 To create clustering index
 CREATE INDEX OrderDateIndex
 ON Order(OrderDate) CLUSTER( for Oracle)
 To create secondary index use CREATE INDEX syntax without specifying
unique.
Clustered Indexes
 A clustered index alters the way that the rows are physically stored.
 When you create a clustered index on a column the database server
sorts the table’s rows by that column(s).
 It is like a dictionary, where all words are sorted in an alphabetical order.
 (**) Note, that only one clustered index can be created per table i.e.
Primarary Key. It alters the way the table is physically stored, it couldn’t
be otherwise.
Non-Clustered Indexes
 It creates a completely different object within the table, that contains the
column(s) selected for indexing and a pointer back to the table’s rows
containing the data.
 It is like an index in the last pages of a book. All keywords are sorted and
contain a reference back to the appropriate page number. A non-
clustered index on the computer_id column, in the previous example,
would look like the table below:
Clustered Vs Non-Clustered Indexes
Overheads of Use of Indexes
 A record is added to the index table every time a new record is added
to the table where there is a secondary index.
 Updating the indexed record means an update to the index table
 More disk space need to store index tables
 Impact on performance if indexes are all consulted every time a query
is run
Sequences
 Sequential numbers that can be used
to increment an ID number
 Equivalent to an auto-number(Identity)
in MS-Sql Server.
De-normalisation
 We have created a database following all the rules of normalisation...
 Now we can break them to make the database work quicker and
perform better...
Roles in a System
 Not every user is the same
 The will need to access different parts of the system and access it in
different ways
SQL Facilities to Manage Roles
 Grant – gives access to an object (such as a table) to a particular role
or user in the database system.
 Revoke – removes access to an object (such as a table) to a particular
role or user in the database system
Grant
 Grant create on Customers to Admin
 Grant all on Customers to Manager
Revoke
 Revoke all on Customers from Admin
 Revoke delete on Customers to Manager
ANY QUESTIONS?
Past Questions Revision
Why does physical design require an understanding of the chosen
DBMS product?
 In physical design the database is designed with the target
Database Management System (DBMS) in mind. Therefore it
entails knowledge of the chosen DBMS whether it is Oracle, MySQL,
SQL Server etc. The particular features of the chosen system might
specify how structures are set up and stored physically new
features get added and older features become obsolete.
Past Questions Revision
 Define the types of information that should be recorded for each table and column at the physical design stage.
 For each table:
• Table name
• List of columns
• Primary key and foreign keys. Any alternate keys
• Referential integrity constraints for each of the foreign keys that have been identified
 For each column:
• The domain of that column including the data-type, length and any additional
constraints that apply to that column
• A default value for the column
• Whether the column is derived and if it is derived then how it is computed
• Whether or not the column can contain null values
Past Questions Revision
Explain the concept of derived data.:
 Derived data is defined as a column whose value is derived
from the value of one or more other columns in the database.
These might be columns within the same table or columns
from one or more other tables.
Past Questions Revision
How can an organization's derived data make the process of
normalization and data design.
 In an organization there is usually a lot of derived data such
as totals for the number of products ordered.
 When looking at documents during normalization we
sometimes come across derived data so we must make sure
that we map its derivation rather than simply duplicating it..
With regard to design there are similar problems to those in
normalization. Also the derived columns will need to be
modeled. Decisions as to how they are modeled need to take
into account aspects like performance.
Past Questions Revision
What role can SQL views play with regard to derived data?
 Views are ways of storing queries across tables They can be
used to store the results of calculations such as those used
with aggregate functions.
Past Questions Revision
Explain with an example the function of database triggers
 Database triggers are pieces of procedural logic that are
attached to database objects that operate (‘fire’) upon some
event happening such as a new row being inserted into the
database.
Past Questions Revision
 Discuss the ways in which a business rule can be enforced in a
database management system.
 Built into the structure of the database through the normal
constraints e.g. a business rule like ‘Every person must have an
address’ would mean that address fields are specified as not null.
 A rule like ‘A student must be enrolled on a course’ would be a
non-null referential integrity constraint (foreign key).
 More complex business rules can be enforced with check
constraints. Applications can also be used to enforce business
rules through the logic of whatever programming language they are
built in.
 Database triggers can also be used to enforce business rules.
Past Questions Revision
 Explain what an index is in a database system.
 Indexes in databases operate in much the same way as an
index in a book. They are separate files that contain location
pointers to the actual rows in the database.
 Instead of a topic title like in a book index they usually
contain one or more attributes that belong to a row.
 They could, for example, contain just customer numbers from
a customer table, rather than all the data for the customers
as the actual database contains.
Past Questions Revision
 Identify and describe THREE (3) different types of index.
 The different types of indexes available are primary index,
secondary index and clustering index.
 A primary index is built around a key field with a unique value
for every entry.
 A secondary index is used for specifying additional key
columns.
 A clustering index is built around a field which can have many
corresponding rows in the table.
Past Questions Revision
 What is a sequence in a database system and what is it used
for?
 A sequence is a structure that generates a number one after
the other. It is used to populate fields such serial numbers
Past Questions Revision
 Outline the process of enforcing referential integrity in a
database system.
 Foreign keys are identified during the design stage of
development when relationships on an ER diagram are
mapped between foreign keys and their referenced parent key
 It is enforced by the use of constraints known as referential
integrity constraints that are created either when the table is
created or later using he alter table command
Past Questions Revision
 With the use of an example define and explain the purpose of
de-normalisation
 De-normalisation is another way of improving performance
De-normalisation involves using replication in a controlled
way.
 Attributes that do not belong to a particular table but are
often retrieved with that table in queries are replicated on that
that table.

More Related Content

What's hot (18)

Supporting Transactions
Supporting TransactionsSupporting Transactions
Supporting Transactions
 
Ch 9 S Q L
Ch 9  S Q LCh 9  S Q L
Ch 9 S Q L
 
Database basics
Database basicsDatabase basics
Database basics
 
Data concepts
Data conceptsData concepts
Data concepts
 
Dbms
DbmsDbms
Dbms
 
Relational database- Fundamentals
Relational database- FundamentalsRelational database- Fundamentals
Relational database- Fundamentals
 
Relational Database Fundamentals
Relational Database FundamentalsRelational Database Fundamentals
Relational Database Fundamentals
 
What is SQL Server?
What is SQL Server?What is SQL Server?
What is SQL Server?
 
Introduction of Database Design and Development
Introduction of Database Design and DevelopmentIntroduction of Database Design and Development
Introduction of Database Design and Development
 
ITCamp 2013 - Cristian Lefter - Transact-SQL from 0 to SQL Server 2012
ITCamp 2013 - Cristian Lefter - Transact-SQL from 0 to SQL Server 2012ITCamp 2013 - Cristian Lefter - Transact-SQL from 0 to SQL Server 2012
ITCamp 2013 - Cristian Lefter - Transact-SQL from 0 to SQL Server 2012
 
SQL
SQL SQL
SQL
 
Introduction to the Structured Query Language SQL
Introduction to the Structured Query Language SQLIntroduction to the Structured Query Language SQL
Introduction to the Structured Query Language SQL
 
Rdbms concepts
Rdbms conceptsRdbms concepts
Rdbms concepts
 
Sql intro & ddl 1
Sql intro & ddl 1Sql intro & ddl 1
Sql intro & ddl 1
 
Structured query language(sql)ppt
Structured query language(sql)pptStructured query language(sql)ppt
Structured query language(sql)ppt
 
Database
DatabaseDatabase
Database
 
The Smartpath Information Systems | BASIC RDBMS CONCEPTS
The Smartpath Information Systems | BASIC RDBMS CONCEPTSThe Smartpath Information Systems | BASIC RDBMS CONCEPTS
The Smartpath Information Systems | BASIC RDBMS CONCEPTS
 
Sql commands
Sql commandsSql commands
Sql commands
 

Similar to Physical Design and Development

Physical elements of data
Physical elements of dataPhysical elements of data
Physical elements of dataDimara Hakim
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developerAhsan Kabir
 
BIS06 Physical Database Models
BIS06 Physical Database ModelsBIS06 Physical Database Models
BIS06 Physical Database ModelsPrithwis Mukerjee
 
BIS06 Physical Database Models
BIS06 Physical Database ModelsBIS06 Physical Database Models
BIS06 Physical Database ModelsPrithwis Mukerjee
 
Database Performance
Database PerformanceDatabase Performance
Database PerformanceBoris Hristov
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfDraguClaudiu
 
Sql ch 12 - creating database
Sql ch 12 - creating databaseSql ch 12 - creating database
Sql ch 12 - creating databaseMukesh Tekwani
 
[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10AnusAhmad
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic ConceptsTony Wong
 
Intro to tsql unit 7
Intro to tsql   unit 7Intro to tsql   unit 7
Intro to tsql unit 7Syed Asrarali
 
05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptxMohamedNowfeek1
 

Similar to Physical Design and Development (20)

Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
 
Physical elements of data
Physical elements of dataPhysical elements of data
Physical elements of data
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developer
 
BIS06 Physical Database Models
BIS06 Physical Database ModelsBIS06 Physical Database Models
BIS06 Physical Database Models
 
BIS06 Physical Database Models
BIS06 Physical Database ModelsBIS06 Physical Database Models
BIS06 Physical Database Models
 
Rdbms day3
Rdbms day3Rdbms day3
Rdbms day3
 
Database Performance
Database PerformanceDatabase Performance
Database Performance
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
 
Database Basics
Database BasicsDatabase Basics
Database Basics
 
Sql ch 12 - creating database
Sql ch 12 - creating databaseSql ch 12 - creating database
Sql ch 12 - creating database
 
[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
 
T-SQL Overview
T-SQL OverviewT-SQL Overview
T-SQL Overview
 
Intro to tsql unit 7
Intro to tsql   unit 7Intro to tsql   unit 7
Intro to tsql unit 7
 
05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
 
Adbms
AdbmsAdbms
Adbms
 
Module02
Module02Module02
Module02
 
Learning SQL
Learning SQLLearning SQL
Learning SQL
 
Module 3
Module 3Module 3
Module 3
 

More from Er. Nawaraj Bhandari

Data mining approaches and methods
Data mining approaches and methodsData mining approaches and methods
Data mining approaches and methodsEr. Nawaraj Bhandari
 
Research trends in data warehousing and data mining
Research trends in data warehousing and data miningResearch trends in data warehousing and data mining
Research trends in data warehousing and data miningEr. Nawaraj Bhandari
 
Mining Association Rules in Large Database
Mining Association Rules in Large DatabaseMining Association Rules in Large Database
Mining Association Rules in Large DatabaseEr. Nawaraj Bhandari
 
Introduction to data mining and data warehousing
Introduction to data mining and data warehousingIntroduction to data mining and data warehousing
Introduction to data mining and data warehousingEr. Nawaraj Bhandari
 
Classification and prediction in data mining
Classification and prediction in data miningClassification and prediction in data mining
Classification and prediction in data miningEr. Nawaraj Bhandari
 
Chapter 3: Simplification of Boolean Function
Chapter 3: Simplification of Boolean FunctionChapter 3: Simplification of Boolean Function
Chapter 3: Simplification of Boolean FunctionEr. Nawaraj Bhandari
 
Chapter 5: Cominational Logic with MSI and LSI
Chapter 5: Cominational Logic with MSI and LSIChapter 5: Cominational Logic with MSI and LSI
Chapter 5: Cominational Logic with MSI and LSIEr. Nawaraj Bhandari
 
Chapter 2: Boolean Algebra and Logic Gates
Chapter 2: Boolean Algebra and Logic GatesChapter 2: Boolean Algebra and Logic Gates
Chapter 2: Boolean Algebra and Logic GatesEr. Nawaraj Bhandari
 
Introduction to Electronic Commerce
Introduction to Electronic CommerceIntroduction to Electronic Commerce
Introduction to Electronic CommerceEr. Nawaraj Bhandari
 
Using macros in microsoft excel part 2
Using macros in microsoft excel   part 2Using macros in microsoft excel   part 2
Using macros in microsoft excel part 2Er. Nawaraj Bhandari
 
Using macros in microsoft excel part 1
Using macros in microsoft excel   part 1Using macros in microsoft excel   part 1
Using macros in microsoft excel part 1Er. Nawaraj Bhandari
 

More from Er. Nawaraj Bhandari (20)

Data mining approaches and methods
Data mining approaches and methodsData mining approaches and methods
Data mining approaches and methods
 
Research trends in data warehousing and data mining
Research trends in data warehousing and data miningResearch trends in data warehousing and data mining
Research trends in data warehousing and data mining
 
Mining Association Rules in Large Database
Mining Association Rules in Large DatabaseMining Association Rules in Large Database
Mining Association Rules in Large Database
 
Introduction to data mining and data warehousing
Introduction to data mining and data warehousingIntroduction to data mining and data warehousing
Introduction to data mining and data warehousing
 
Data warehouse testing
Data warehouse testingData warehouse testing
Data warehouse testing
 
Data warehouse physical design
Data warehouse physical designData warehouse physical design
Data warehouse physical design
 
Data warehouse logical design
Data warehouse logical designData warehouse logical design
Data warehouse logical design
 
Classification and prediction in data mining
Classification and prediction in data miningClassification and prediction in data mining
Classification and prediction in data mining
 
Chapter 3: Simplification of Boolean Function
Chapter 3: Simplification of Boolean FunctionChapter 3: Simplification of Boolean Function
Chapter 3: Simplification of Boolean Function
 
Chapter 6: Sequential Logic
Chapter 6: Sequential LogicChapter 6: Sequential Logic
Chapter 6: Sequential Logic
 
Chapter 5: Cominational Logic with MSI and LSI
Chapter 5: Cominational Logic with MSI and LSIChapter 5: Cominational Logic with MSI and LSI
Chapter 5: Cominational Logic with MSI and LSI
 
Chapter 4: Combinational Logic
Chapter 4: Combinational LogicChapter 4: Combinational Logic
Chapter 4: Combinational Logic
 
Chapter 2: Boolean Algebra and Logic Gates
Chapter 2: Boolean Algebra and Logic GatesChapter 2: Boolean Algebra and Logic Gates
Chapter 2: Boolean Algebra and Logic Gates
 
Chapter 1: Binary System
 Chapter 1: Binary System Chapter 1: Binary System
Chapter 1: Binary System
 
Introduction to Electronic Commerce
Introduction to Electronic CommerceIntroduction to Electronic Commerce
Introduction to Electronic Commerce
 
Evaluating software development
Evaluating software developmentEvaluating software development
Evaluating software development
 
Using macros in microsoft excel part 2
Using macros in microsoft excel   part 2Using macros in microsoft excel   part 2
Using macros in microsoft excel part 2
 
Using macros in microsoft excel part 1
Using macros in microsoft excel   part 1Using macros in microsoft excel   part 1
Using macros in microsoft excel part 1
 
Using macros in microsoft access
Using macros in microsoft accessUsing macros in microsoft access
Using macros in microsoft access
 
Testing software development
Testing software developmentTesting software development
Testing software development
 

Recently uploaded

Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxFurkanTasci3
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts ServiceSapana Sha
 
Spark3's new memory model/management
Spark3's new memory model/managementSpark3's new memory model/management
Spark3's new memory model/managementakshesh doshi
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubaihf8803863
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSAishani27
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfgstagge
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiSuhani Kapoor
 
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...Pooja Nehwal
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...shivangimorya083
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...dajasot375
 
Data Science Project: Advancements in Fetal Health Classification
Data Science Project: Advancements in Fetal Health ClassificationData Science Project: Advancements in Fetal Health Classification
Data Science Project: Advancements in Fetal Health ClassificationBoston Institute of Analytics
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystSamantha Rae Coolbeth
 

Recently uploaded (20)

Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptx
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts Service
 
Spark3's new memory model/management
Spark3's new memory model/managementSpark3's new memory model/management
Spark3's new memory model/management
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICS
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdf
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
 
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
 
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
 
Data Science Project: Advancements in Fetal Health Classification
Data Science Project: Advancements in Fetal Health ClassificationData Science Project: Advancements in Fetal Health Classification
Data Science Project: Advancements in Fetal Health Classification
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data Analyst
 

Physical Design and Development

  • 1. Er. Nawaraj Bhandari Database Design & Developmentf Topic 7 & 8: Physical Design 2
  • 2. Types of Constraints  Entity integrity  Referential integrity  Propagation constraints  Domain constraints  Table constraints
  • 3. Activity – Recap - 1  What is the Entity integrity rule?  What is referential integrity?
  • 4. Activity – Recap - 2  What is the Entity integrity rule?  The primary key of an entity cannot contain nulls.  What is referential integrity?  If a foreign key contains a value then that value must refer to an existing tuple in the source table
  • 5. The Art Suppliers data model - where will there need to be constraints? Order OrderItem Item Supplier 1 1 1 0...* 0...* 0...* Customer 1 0...*
  • 6. Source or Parent Table Create table customers (CustomerNo integer(5) not null, first_name varchar(30), last_name varchar(30), primary key emp_no);
  • 7. Referencing or Child Table Create table Orders (OrderID integer(5) not null, CustomerID integer(5) not null, OrderDate datetime, primary key OrderID, foreign key (CustomerID) references Customer (CustomerID);
  • 8. Referential Integrity Constraint – Another Example Create table workers (emp_no integer(5) not null, first_name varchar(30), last_name varchar(30), job_title varchar(30), age integer(3), dept_no integer(5), primary key emp_no, foreign key (dept_no) references Departments (dept_no)o)
  • 9. Propagation Constraint  What happens if we delete a Item from our Art Supply database?  There are lots of OrderItem records that reference it. What happens to them?
  • 10. Options for Propagation  No action  Cascade  Set Default  Set Null
  • 11. Table with Propagation Constraint with no action and cascade Create Table Item (ItemID integer NOT NULL, SupplierID integer NOT NULL, Price float, Primary Key (ItemID), Foreign Key (SupplierID) REFERENCES Supplier(SupplierID) On delete no action On update cascade);
  • 12. Table with Propagation Constraint with Set Default
  • 13. Table with Propagation Constraint with no action and cascade Create Table Item (ItemID integer NOT NULL, SupplierID integer NOT NULL, Price float, Primary Key (ItemID), Foreign Key (SupplierID) REFERENCES Supplier(SupplierID) On delete set Null On update set Null);
  • 14. Domain Constraints  Product Type could be enforced as...  a check constraint  separate domain using Create Domain statement  as a foreign key to another table
  • 15. Check Constraint Create Table ProductType (ProductTypeID integer NOT NULL, ProductTypeName varchar (30) NOT NULL, ProductTypeColour varchar (20), Primary Key (ProductTypeID) Check (ProductTypeColour in ‘Red’,’Blue’,’Green’));
  • 16. As a Separate Domain Create Domain ProductTypeColour As varchar(20) Default ‘Red’ Check (Value in (‘Red’,’Blue’,’Green’));  The table’ProductType’ will set the ProductTypeColour attribute as this domain ProductTypeColour Create Table ProductType (ProductTypeID integer NOT NULL, ProductTypeName varchar (30) NOT NULL, ProductTypeColour BoatType, Primary Key (ProductTypeID));
  • 17. As a Separate Table Create Table ProductTypeColour( (ProductTypeColourCode Varchar(3), ProductTypeColourDescription Varchar(20) Primary Key (ProductTypeColourCode)); With the corresponding Foreign Key in Boat Create Table ProductType (ProductTypeID integer NOT NULL, ProductTypeName varchar (30) NOT NULL, ProductTypeColour varchar (3), Primary Key (ProductTypeID) Foreign Key (ProductTypeColourCode) References ProductTypeColour (ProductTypeColourCode));
  • 18. Business Rules Enforced by Constraints  Business rules are derived from requirements analysis and documented in logical design  They depend on the operations of the ‘real world’ business
  • 19. Business Rule: No order may contain more than 10 OrderItems Order OrderItem Item Supplier 1 1 1 0...* 0...10 0...* Customer 1 0...*
  • 20. Table Constraints Create Table Orders ( (OrderID integer NOT NULL, CustomerID integer NOT NULL, OrderDate datetime NOT NULL Constraint MaximumOrderItems Check(Not Exists(Select OrderID From OrderItems Group By OrderID Having Count(*) >10)), Primary Key (OrderID) Foreign Key (CustomerID) REFERENCES Customer(CustomerID) On delete no action On update cascade);
  • 21. Table Constraints – Another Example Create Table Rental ( (BoatID integer NOT NULL, CustomerID integer NOT NULL, RentalStartDate datetime NOT NULL, RentalEndDate datetime NOT NULL Constraint MaximumRentals Check(Not Exists(Select BoatID From Rentals Group By BoatID Having Count(*) >10)), Primary Key (BoatID, CustomerID, RentalStartDate) Foreign Key (CustomerID) REFERENCES Customer(CustomerID), Foreign Key (BoatID) REFERENCES Boat (BoatID) On delete no action On update cascade);
  • 22. Some Additional Database Structures  Views  Indexes  Sequences
  • 23. View of selected rows or columns of these tables Improving Performance with the use of Views Table 1 Table 2 Table 3 Query
  • 24. Example of Creating a View Create View OrderSummary as (Select O.OrderID, O.OrderDate, I.ItemName, I.Price, OI.Quantity, O.Total From Orders O, OrderItems OI, Items I Where O.OrderID = OrderItems.OrderID And I.ItemID = OI.ItemID);  What will be the purpose of this view?
  • 25. Indexes  Improve performance.  They work by creating entries in a special structure that makes it easier to find a record
  • 26. Index Types  Primary index  Secondary index  Clustering index
  • 27. Primary Index  Built around a key field that is used for ordering. A unique value for every entry in the index.
  • 28. Secondary Index  Defined on a non-ordering field  May not contain unique values  Improves the performance of queries that use columns other than primary key
  • 29. Use of Secondary Indexes  Mechanism for specifying additional key columns.  For example Customer would be searched often on Customer Name as well as the primary key and so a secondary index could be used on it.
  • 30. Examples of Creating Indexes in SQL  To create primary index  CREATE UNIQUE INDEX CustomerIDIndex  ON Customer(CustomerID)  To create clustering index  CREATE INDEX OrderDateIndex  ON Order(OrderDate) CLUSTER( for Oracle)  To create secondary index use CREATE INDEX syntax without specifying unique.
  • 31. Clustered Indexes  A clustered index alters the way that the rows are physically stored.  When you create a clustered index on a column the database server sorts the table’s rows by that column(s).  It is like a dictionary, where all words are sorted in an alphabetical order.  (**) Note, that only one clustered index can be created per table i.e. Primarary Key. It alters the way the table is physically stored, it couldn’t be otherwise.
  • 32. Non-Clustered Indexes  It creates a completely different object within the table, that contains the column(s) selected for indexing and a pointer back to the table’s rows containing the data.  It is like an index in the last pages of a book. All keywords are sorted and contain a reference back to the appropriate page number. A non- clustered index on the computer_id column, in the previous example, would look like the table below:
  • 34. Overheads of Use of Indexes  A record is added to the index table every time a new record is added to the table where there is a secondary index.  Updating the indexed record means an update to the index table  More disk space need to store index tables  Impact on performance if indexes are all consulted every time a query is run
  • 35. Sequences  Sequential numbers that can be used to increment an ID number  Equivalent to an auto-number(Identity) in MS-Sql Server.
  • 36. De-normalisation  We have created a database following all the rules of normalisation...  Now we can break them to make the database work quicker and perform better...
  • 37. Roles in a System  Not every user is the same  The will need to access different parts of the system and access it in different ways
  • 38. SQL Facilities to Manage Roles  Grant – gives access to an object (such as a table) to a particular role or user in the database system.  Revoke – removes access to an object (such as a table) to a particular role or user in the database system
  • 39. Grant  Grant create on Customers to Admin  Grant all on Customers to Manager
  • 40. Revoke  Revoke all on Customers from Admin  Revoke delete on Customers to Manager
  • 42. Past Questions Revision Why does physical design require an understanding of the chosen DBMS product?  In physical design the database is designed with the target Database Management System (DBMS) in mind. Therefore it entails knowledge of the chosen DBMS whether it is Oracle, MySQL, SQL Server etc. The particular features of the chosen system might specify how structures are set up and stored physically new features get added and older features become obsolete.
  • 43. Past Questions Revision  Define the types of information that should be recorded for each table and column at the physical design stage.  For each table: • Table name • List of columns • Primary key and foreign keys. Any alternate keys • Referential integrity constraints for each of the foreign keys that have been identified  For each column: • The domain of that column including the data-type, length and any additional constraints that apply to that column • A default value for the column • Whether the column is derived and if it is derived then how it is computed • Whether or not the column can contain null values
  • 44. Past Questions Revision Explain the concept of derived data.:  Derived data is defined as a column whose value is derived from the value of one or more other columns in the database. These might be columns within the same table or columns from one or more other tables.
  • 45. Past Questions Revision How can an organization's derived data make the process of normalization and data design.  In an organization there is usually a lot of derived data such as totals for the number of products ordered.  When looking at documents during normalization we sometimes come across derived data so we must make sure that we map its derivation rather than simply duplicating it.. With regard to design there are similar problems to those in normalization. Also the derived columns will need to be modeled. Decisions as to how they are modeled need to take into account aspects like performance.
  • 46. Past Questions Revision What role can SQL views play with regard to derived data?  Views are ways of storing queries across tables They can be used to store the results of calculations such as those used with aggregate functions.
  • 47. Past Questions Revision Explain with an example the function of database triggers  Database triggers are pieces of procedural logic that are attached to database objects that operate (‘fire’) upon some event happening such as a new row being inserted into the database.
  • 48. Past Questions Revision  Discuss the ways in which a business rule can be enforced in a database management system.  Built into the structure of the database through the normal constraints e.g. a business rule like ‘Every person must have an address’ would mean that address fields are specified as not null.  A rule like ‘A student must be enrolled on a course’ would be a non-null referential integrity constraint (foreign key).  More complex business rules can be enforced with check constraints. Applications can also be used to enforce business rules through the logic of whatever programming language they are built in.  Database triggers can also be used to enforce business rules.
  • 49. Past Questions Revision  Explain what an index is in a database system.  Indexes in databases operate in much the same way as an index in a book. They are separate files that contain location pointers to the actual rows in the database.  Instead of a topic title like in a book index they usually contain one or more attributes that belong to a row.  They could, for example, contain just customer numbers from a customer table, rather than all the data for the customers as the actual database contains.
  • 50. Past Questions Revision  Identify and describe THREE (3) different types of index.  The different types of indexes available are primary index, secondary index and clustering index.  A primary index is built around a key field with a unique value for every entry.  A secondary index is used for specifying additional key columns.  A clustering index is built around a field which can have many corresponding rows in the table.
  • 51. Past Questions Revision  What is a sequence in a database system and what is it used for?  A sequence is a structure that generates a number one after the other. It is used to populate fields such serial numbers
  • 52. Past Questions Revision  Outline the process of enforcing referential integrity in a database system.  Foreign keys are identified during the design stage of development when relationships on an ER diagram are mapped between foreign keys and their referenced parent key  It is enforced by the use of constraints known as referential integrity constraints that are created either when the table is created or later using he alter table command
  • 53. Past Questions Revision  With the use of an example define and explain the purpose of de-normalisation  De-normalisation is another way of improving performance De-normalisation involves using replication in a controlled way.  Attributes that do not belong to a particular table but are often retrieved with that table in queries are replicated on that that table.

Editor's Notes

  1. clustered index determines the physical order of the rows in the database
  2. clustered index determines the physical order of the rows in the database
  3. clustered index determines the physical order of the rows in the database