Er. Nawaraj Bhandari
Topic 11
Implementation
Types of Constraints
 Referential Integrity Constraints
 Propagation Constraints
 Domain Constraints
 Table Constraints

 Plus...
 Constraint Violation
Referential Integrity Constraint
Create table workers
(emp_no number(5) not null,
first_name varchar(30),
last_name varchar(30),
job_title varchar(30),
age number(3),
dept_no number(5),
primary key emp_no,
foreign key (dept_no) references
Propagation Constraint
 What happens if we delete a Boat from our Boat Hire database?
 There are lots of Rental records that reference it. What happens to
them?
Table with Propagation Constraint
Create Table Rental
(BoatID number NOT NULL,
CustomerID number NOT NULL,
RentalStartDate date NOT NULL,
RentalEndDate date NOT NULL,
Primary Key (BoatID, CustomerID, RentalStartDate)
Foreign Key (CustomerID) REFERENCES Customer(CustomerID),
Foreign Key (BoatID) REFERENCES Boat (BoatID)
On delete no action
On update cascade);
Options for Propagation
 No action
 Cascade
 Set Default
 Set Null
Domain Constraints
 Boat 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 Boat
(BoatID number NOT NULL,
BoatName varchar (30) NOT NULL,
BoatType varchar (20),
Primary Key (BoatID)
Check (BoatType in ‘Yacht’,’Cruiser’,’Rower’));
As a Separate Domain
 Create Domain BoatType As varchar(20)
 Default ‘Yacht’
 Check (Value in (‘Yacht’,’Cruiser’,’Rower’));
 The table’Boat’ will set the BoatType attribute as this domain
BoatType.
As a Separate Table
Create Table BoatType
(BoatTypeCode Varchar(3),
BoatTypeDescription Varchar(20)
Primary Key (BoatTypeCode));
With the corresponding Foreign Key in Boat
Create Table Boat
(BoatID number NOT NULL,
BoatName varchar (30) NOT NULL,
BoatTypeCode varchar (3),
Primary Key (BoatID)
Foreign Key (BoatTypeCode) References BoatType;
Table Constraints
Create Table Rental
(BoatID number NOT NULL,
CustomerID number NOT NULL,
RentalStartDate date NOT NULL,
RentalEndDate date 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(Custo
Foreign Key (BoatID) REFERENCES Boat (BoatID)
On delete no action
On update cascade);
This constraint is checked if there is any
modification to a row, regardless the value of the
column changed or not.
In column constraint the condition is checked
when the value of the column changed.
Eg Domain Constraints
Inserting Data
 The basic SQL feature for inserting multiple rows:
 INSERT INTO ''TABLE'' (''column-name'', [''column-name', ...])
 VALUES (''1st row value a'',"1st row value b"),
 (''2nd row value a', "2nd row value b"),
 ...
 Example
 Insert into boats (boatID, boatName)
 Values (1,'Esmerelda'),
 (2,'Missy'),
 (3,'Lord George');
Data Loading Tools
 Bulk insert in SQL server
 http://sqlserver2000.databases.aspfaq.com/how-do-i-load-
text-or-csv-file-data-into-sql-server.html
 Oracle SQL loader
 http://oreilly.com/catalog/orsqlloader/chapter/ch01.html
 My-SQL uses something called 'Bulk Insert'
 http://mysql.bigresource.com/Bulk-insert-from-text-files-
dDPRzHYo.html#2t6P0D5I
Server
Database
Network
Internet
Server
Applications
Other systems
http://192.168.2.223:5560/isqlplus
Oracle
 For many years, Oracle was the largest market share AND largest by value.
 It was challenged recently by MySQL.
Support for Languages
 Java Programming – allowing sophisticated manipulation
of data using the logic of a programming language
 XML – allowing development of own tags so capable of
transmitting data in almost any format
Support for...
 Distributed database features
 Advanced security
 Data warehousing
 Internet ready features
Objects
 Tables, indexes, views, domains...
 More complex objects with internal structure
 PL/SQL
 Stored functions
 Stored procedures
 Triggers
Oracle Architecture
 Database
 Database Instance
 Logical and Physical structure
Logical Structure of Oracle
 Tables spaces – logical storage units that contain the other objects,
which have memory divided into blocks, extents, and segments.
 Database schemas contain or own the objects like tables.
 Definition of users
Physical Structure of Oracle
 Datafiles
Database datafiles are physical files stored on disk. These files are used to store data on disk.
Database datafiles are only written to by the DBWR processes
 Redo logs
Like a tape recorder that records every change in the Oracle database. As changes occur, they
are regularly recorded in the online redo logs, just like you might record a movie on your VCR.
 Control files
The Control File of the database is a binary file that contains a great deal of database
information. The control file contains the database name, data about the database log files.
Oracle cannot function without valid control files.
Oracle Instance
 Contains all the processes and memory areas.
 A database instance is a set of memory structures that manage database files
 The instance manages its associated data and serves the users of the database.
 Also contains...
Oracle Instance
- System Global Area: When an instance is started, Oracle Database allocates a
memory area called the SGA.
- Program Global Area: A PGA is a memory region that contains data and control
information for a server process. It is no shared memory created by Oracle
Database when a server process is started
- User Processes: User roles and user management
References
 Benyon-Davis, P. (2003). Database Systems, 3rd edition. Palgrave Macmillan.
Chapter 12.
 Connolly, T. & Begg, C. (2004). Database Systems: A Practical Approach to
Design, Implementation, and Management, 4th Edition. Addison Wesley.
Chapters 8 & 17.
ANY QUESTIONS?

Database Architecture

  • 1.
    Er. Nawaraj Bhandari Topic11 Implementation
  • 2.
    Types of Constraints Referential Integrity Constraints  Propagation Constraints  Domain Constraints  Table Constraints   Plus...  Constraint Violation
  • 3.
    Referential Integrity Constraint Createtable workers (emp_no number(5) not null, first_name varchar(30), last_name varchar(30), job_title varchar(30), age number(3), dept_no number(5), primary key emp_no, foreign key (dept_no) references
  • 4.
    Propagation Constraint  Whathappens if we delete a Boat from our Boat Hire database?  There are lots of Rental records that reference it. What happens to them?
  • 5.
    Table with PropagationConstraint Create Table Rental (BoatID number NOT NULL, CustomerID number NOT NULL, RentalStartDate date NOT NULL, RentalEndDate date NOT NULL, Primary Key (BoatID, CustomerID, RentalStartDate) Foreign Key (CustomerID) REFERENCES Customer(CustomerID), Foreign Key (BoatID) REFERENCES Boat (BoatID) On delete no action On update cascade);
  • 6.
    Options for Propagation No action  Cascade  Set Default  Set Null
  • 7.
    Domain Constraints  BoatType could be enforced as...  a check constraint  separate domain using Create Domain statement  as a foreign key to another table
  • 8.
    Check Constraint Create TableBoat (BoatID number NOT NULL, BoatName varchar (30) NOT NULL, BoatType varchar (20), Primary Key (BoatID) Check (BoatType in ‘Yacht’,’Cruiser’,’Rower’));
  • 9.
    As a SeparateDomain  Create Domain BoatType As varchar(20)  Default ‘Yacht’  Check (Value in (‘Yacht’,’Cruiser’,’Rower’));  The table’Boat’ will set the BoatType attribute as this domain BoatType.
  • 10.
    As a SeparateTable Create Table BoatType (BoatTypeCode Varchar(3), BoatTypeDescription Varchar(20) Primary Key (BoatTypeCode)); With the corresponding Foreign Key in Boat Create Table Boat (BoatID number NOT NULL, BoatName varchar (30) NOT NULL, BoatTypeCode varchar (3), Primary Key (BoatID) Foreign Key (BoatTypeCode) References BoatType;
  • 11.
    Table Constraints Create TableRental (BoatID number NOT NULL, CustomerID number NOT NULL, RentalStartDate date NOT NULL, RentalEndDate date 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(Custo Foreign Key (BoatID) REFERENCES Boat (BoatID) On delete no action On update cascade); This constraint is checked if there is any modification to a row, regardless the value of the column changed or not. In column constraint the condition is checked when the value of the column changed. Eg Domain Constraints
  • 12.
    Inserting Data  Thebasic SQL feature for inserting multiple rows:  INSERT INTO ''TABLE'' (''column-name'', [''column-name', ...])  VALUES (''1st row value a'',"1st row value b"),  (''2nd row value a', "2nd row value b"),  ...  Example  Insert into boats (boatID, boatName)  Values (1,'Esmerelda'),  (2,'Missy'),  (3,'Lord George');
  • 13.
    Data Loading Tools Bulk insert in SQL server  http://sqlserver2000.databases.aspfaq.com/how-do-i-load- text-or-csv-file-data-into-sql-server.html  Oracle SQL loader  http://oreilly.com/catalog/orsqlloader/chapter/ch01.html  My-SQL uses something called 'Bulk Insert'  http://mysql.bigresource.com/Bulk-insert-from-text-files- dDPRzHYo.html#2t6P0D5I
  • 14.
  • 15.
    Oracle  For manyyears, Oracle was the largest market share AND largest by value.  It was challenged recently by MySQL.
  • 16.
    Support for Languages Java Programming – allowing sophisticated manipulation of data using the logic of a programming language  XML – allowing development of own tags so capable of transmitting data in almost any format
  • 17.
    Support for...  Distributeddatabase features  Advanced security  Data warehousing  Internet ready features
  • 18.
    Objects  Tables, indexes,views, domains...  More complex objects with internal structure  PL/SQL  Stored functions  Stored procedures  Triggers
  • 19.
    Oracle Architecture  Database Database Instance  Logical and Physical structure
  • 20.
    Logical Structure ofOracle  Tables spaces – logical storage units that contain the other objects, which have memory divided into blocks, extents, and segments.  Database schemas contain or own the objects like tables.  Definition of users
  • 21.
    Physical Structure ofOracle  Datafiles Database datafiles are physical files stored on disk. These files are used to store data on disk. Database datafiles are only written to by the DBWR processes  Redo logs Like a tape recorder that records every change in the Oracle database. As changes occur, they are regularly recorded in the online redo logs, just like you might record a movie on your VCR.  Control files The Control File of the database is a binary file that contains a great deal of database information. The control file contains the database name, data about the database log files. Oracle cannot function without valid control files.
  • 22.
    Oracle Instance  Containsall the processes and memory areas.  A database instance is a set of memory structures that manage database files  The instance manages its associated data and serves the users of the database.  Also contains...
  • 23.
    Oracle Instance - SystemGlobal Area: When an instance is started, Oracle Database allocates a memory area called the SGA. - Program Global Area: A PGA is a memory region that contains data and control information for a server process. It is no shared memory created by Oracle Database when a server process is started - User Processes: User roles and user management
  • 24.
    References  Benyon-Davis, P.(2003). Database Systems, 3rd edition. Palgrave Macmillan. Chapter 12.  Connolly, T. & Begg, C. (2004). Database Systems: A Practical Approach to Design, Implementation, and Management, 4th Edition. Addison Wesley. Chapters 8 & 17.
  • 25.

Editor's Notes

  • #15 Try to describe the client/server architecture of oracle. In the Oracle Database environment, the database application and the database are separated into a client/server architecture: The client runs the database application, for example, SQL*Plus or a Visual Basic data entry program, that accesses database information and interacts with a user. Try to follow this link as well https://www.wiziq.com/tutorial/167572-CLIENT-SERVER-ARCHITECTURE-IN-DATABASE
  • #17 Extensible Markup Language