Standards and Conventions

Slides:



Advertisements
Similar presentations
CIT 613: Relational Database Development using SQL Revision of Tables and Data Types.
Advertisements

The Relational Model Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
Relational Database Design UNIT II 1. 2 Advantages of Using Database Systems Centralized control of a firm’s data Redundancy can be reduced (avoid keeping.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
The Relational Model. Introduction Introduced by Ted Codd at IBM Research in 1970 The relational model represents data in the form of table. Main concept.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
CS 380 Introduction to Database Systems (Chapter 5: The Relational Data Model and Relational Database Constraints)
Database Lecture # 1 By Ubaid Ullah.
Module Title? DBMS E-R Model to Relational Model.
Content Resource- Elamsari and Navathe, Fundamentals of Database Management systems.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
Relational Database Management Systems. A set of programs to manage one or more databases Provides means for: Accessing the data Inserting, updating and.
1 The Relational Model Instructor: Mohamed Eltabakh
CG084&085 / / 1 The Relational Data Model Properties of Relations Keys and Constraints.
MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj ER Model Lecture 1 © Akhilesh Bajaj, 2000, 2002, 2003, 2004.
Common Field Types Primary Key Descriptive Fields Foreign Key.
Relational Data Model Ch. 7.1 – 7.3 John Ortiz Lecture 3Relational Data Model2 Why Study Relational Model?  Most widely used model.  Vendors: IBM,
11 3 / 12 CHAPTER Databases MIS105 Lec15 Irfan Ahmed Ilyas.
DAT602 Database Application Development Lecture 2 Review of Relational Database.
Data modeling using the entity-relationship model Chapter 3 Objectives How entities, tuples, attributes and relationships among entities are represented.
UNIT_2 1 DATABASE MANAGEMENT SYSTEM[DBMS] [Unit: 2] Prepared By Lavlesh Pandit SPCE MCA, Visnagar.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
IMS 4212: Data Modeling—Attributes and Domains 1 Dr. Lawrence West, Management Dept., University of Central Florida Attributes and Domains.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.
SQL constrains and keys. SORTED RESULTS Sort the results by a specified criterion SELECT columns FROM tables WHERE predicates ORDER BY column ASC/DESC;
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
Chapter 71 The Relational Data Model, Relational Constraints & The Relational Algebra.
Database Constraints Ashima Wadhwa. Database Constraints Database constraints are restrictions on the contents of the database or on database operations.
ER Diagrams and Relational Model CS 174a (Winter 2015)
COP Introduction to Database Structures
Getting started with Accurately Storing Data
Creating Database Objects
Fundamentals of DBMS Notes-1.
Logical Database Design and the Rational Model
Entity-Relationship Model
Database Constraints Ashima Wadhwa.
Chapter 5 Database Design
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Databases Chapter 16.
Chapter 2: Relational Model
Entity-Relationship Model
LIS 384K.11 Database-Management Principles and Applications
Data Definition and Data Types
Tables and Their Characteristics
CSIS 115 Database Design and Applications for Business
Attributes and Domains
Entity-Relationship Model
Translation of ER-diagram into Relational Schema
Entity Relationship Diagram
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Instructor: Mohamed Eltabakh
Data Modelling Introduction
ERD’s REVIEW DBS201.
IST 318 Database Administration
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
Chapter 3: Modeling Data in the Organization
Attributes and Domains
Database Design: Relational Model
Mapping an ERD to a Relational Database
Instructor: Mohamed Eltabakh
INSTRUCTOR: MRS T.G. ZHOU
Creating Database Objects
SQL (Structured Query Language)
Chapter 3 The Relational Model
RELATIONAL DATA MODEL - 1
Presentation transcript:

Standards and Conventions Relational Database Standards and Conventions

Relation/Table Rows / Tuples Columns / fields Attributes Records Keys Constraints

Tuple and Column Tuple is a table row.

Cardinality vs Degree Cardinality is total no of rows in a table. Degree is total no of columns in a table

Attribute Type Domain Data type

Attribute Type Key and non-key Required and optional Single and composite Single-valued and multi-valued Derived

EXERCISE Classify the following attributes: First Name Full Name Years Employed Race Roll no Hobbies Date Employed Password Today’s Date Last Name TransactionID

Solution Classifications of the following attributes: First Name – Simple, Required Full Name – Composite (FirstName. LastName) [Years Employed] – Derived (DateEmployed, Today’s Date) Race -- Simple Roll no – Identifier {Hobbies} – Multivalued, Optional Date Employed -- Simple Password – Simple, Required Today’s Date – Simple(Can be composite if dd-mm-yyyy) Last Name -- Simple TransactionID – Composite Identifier (OrderID, OrderLine)

Attribute Domain A domain is defined as the set of all unique values permitted for an attribute. For example, a domain of date is the set of all possible valid dates a domain of integer is all possible whole numbers a domain of day-of-week is Monday, Tuesday ... Sunday. gender may have the domain {male, female, unknown}

Data types Exact Numeric Data Types Approximate Numeric Data Types Date and Time Data Types Character Strings Data Types Image Data Type

Exact Numeric Data Types FROM TO bigint -9,223,372,036,854,775,808 9,223,372,036,854,775,807 int -2,147,483,648 2,147,483,647 smallint -32,768 32,767 tinyint 255 bit 1 decimal -10^38 +1 10^38 -1 numeric money -922,337,203,685,477.5808 +922,337,203,685,477.5807 smallmoney -214,748.3648 +214,748.3647

Approximate Numeric Data Types FROM TO float -1.79E + 308 1.79E + 308 real -3.40E + 38 3.40E + 38

Date and Time Data Types FROM TO datetime Jan 1, 1753 Dec 31, 9999 smalldatetime Jan 1, 1900 Jun 6, 2079 date Stores a date like June 30, 1991 time Stores a time of day like 12:30 P.M.

Character Strings Data Types Description char Maximum length of 8,000 characters.( Fixed length non-Unicode characters) varchar Maximum of 8,000 characters.(Variable-length non-Unicode data). varchar(max) Maximum length of 231characters, Variable-length non-Unicode data (SQL Server 2005 only). text Variable-length non-Unicode data with a maximum length of 2,147,483,647 characters.

Image Data Type DATA TYPE Description image Maximum length of 2,147,483,647 bytes. ( Variable length Binary Data)

Record A record contains all the information about a single ‘member’ of a table. It is a collection of attributes.  Records are also known as tuples.

Keys One or more columns in a database table that is used to sort and/or identify rows in a table. Keys are also used to create relationship among different database tables.

Types of keys Primary key Unique Key Foreign key Candidate key Super key Simple key Compound key Composite key Surrogate key Alternate key Secondary Key

Primary key A primary key is a one or more fields that uniquely identifies a row in a table. It can not accept null and duplicate values. A relation can have only one primary key. E:g. ID, SSN, Credit card no, Reg no, Roll no

Unique Key Unique key is a set of one or more fields/columns of a table that uniquely identify a record in database table. It is like Primary key but it can accept only one null value. It can not have duplicate values. We can have more than one unique keys in a table.  E:g. mobile no, enroll no

Foreign key A foreign key in one table refers to the primary key (PK) of another table. A foreign key is generally a primary key from one table that appears as a field in another where the first table has a relationship to the second. In other words, if we had a table A with a primary key X that linked to a table B where X was a field in B, then X would be a foreign key in B.

Foreign key example

Candidate key A candidate key is a field or combination of fields that can act as a primary key field for that table to uniquely identify each record in that table. It must contain unique values It must not contain null values It contains the minimum number of fields to ensure uniqueness It must uniquely identify each record in the table Once your candidate keys have been identified you can now select one to be your primary key E:g. Reg no and credit card no.

Super key A Super key is any combination of fields within a table that uniquely identifies each record within that table. It is the most general key. E:g. ID ID, Name ID, Address ID, Department_ID ID, Salary Name, Address

Simple key  A simple key consists of a single field to uniquely identify a record. In addition the field in itself cannot be broken down into other fields, for example, studentId, which uniquely identifies a particular student, is a single field and therefore is a simple key. No two students would have the same student number.

Alternate key An alternate key is any candidate key which is not selected to be the primary key. E.g. of Alternate Key is “Name, Address” as it is the only other Candidate Key which is not a Primary Key.

Secondary Key The attributes that are not even the Super Key but can be still used for identification of records (not unique) are known as Secondary Key. E.g. of Secondary Key can be Name, Address, Salary, Department_ID etc. as they can identify the records but they might not be unique.

Compound key A compound key consists of more than one field to uniquely identify a record. A compound key is distinguished from a composite key because each field, which makes up the primary key, is also a simple key in its own right. An example might be a table that represents the course a student is attending. This table has a studentId and a course Code as its primary key. Each of the fields that make up the primary key are simple keys because each represents a unique reference when identifying a student in one instance and a course in the other.

Composite key A composite key consists of more than one field to uniquely identify a record. This differs from a compound key in that one or more of the attributes, which make up the key, are not simple keys in their own right. Taking the example from compound key, imagine we identified a student by their firstName + lastName. In our table representing students on courses our primary key would now be firstName + lastName + courseCode. Because firstName + lastName represent a unique reference to a student, they are not each simple keys, they have to be combined in order to uniquely identify the student. Therefore the key for this table is a composite key.

Surrogate key A primary key which is internally generated (typically auto-incremental integer value) that does not exist in the real world i.e. ID=1 for Customer A and ID=2 for Customer B serves to uniquely identify the record but has no bearing the customer themselves and is an attribute they will never (need to) be aware of.

Exercise ID Roll no Name Enroll no Address Dept ID Dept ID Name

Solution

Constraints Constraints are the rules enforced on data columns on table. These are used to limit the type of data that can go into a table. This ensures the accuracy and reliability of the data in the database. Constraints could be column level or table level. Column level constraints are applied only to one column, whereas table level constraints are applied to the whole table.

Types of Constraints NOT NULL Constraint: Ensures that a column cannot have NULL value. DEFAULT Constraint: Provides a default value for a column when none is specified. UNIQUE Constraint: Ensures that all values in a column are different. PRIMARY Key: Uniquely identified each rows/records in a database table. FOREIGN Key: Uniquely identified a rows/records in any another database table. CHECK Constraint: The CHECK constraint ensures that all values in a column satisfy certain conditions. INDEX: Use to create and retrieve data from the database very quickly.

Example

PROPERTIES OF RELATIONS P1: There are no duplicate tuples.  P2: Tuples are unordered.  P3: Attributes are unordered.  P4: All attribute values are atomic.  P5: No two tables can have the same name in a database. P6: Attributes (columns) cannot have the same name in a table.   P7: All values within an attribute are from the same domain.