Professional Documents
Culture Documents
Chapter 1
Chapter 1
Chapter 1
RDBMS Concepts
Introduction
A database is a collection of data that is organized such that its contents can be easily accessed, managed, and updated. In this session, we will see how a database is designed.
DMBS A Recap
Organizations used to maintain their data in Database Management System (DBMS). The main drawback of DBMSs was that the data was stored in a flat file format. Information on different objects was maintained separately in different physical files. Hence, the relations between these objects, if any, also had to be maintained in separate physical files. Thus, a single package would contain a number of data files, and programming files that were required to integrate them into a single system.
A solution to these problems came in the form of a centralized database system. In a centralized database system, the database is stored at a central location . Every user has access to the database , and the data stored in it from each users machine. For example, a large central database system would contain all the data pertaining to the employees of an organization. The accounts and the HRD departament would use suitable programs to access this data. These programs, or the entire application would reside on individual computer terminals.
A database management system is similar to the filing cabinets that we use to organize our papers. These cabinets provide centralized control of data. When we have new papers to be filed , we add those sheets to existing files. When a particular document or paper is required, it can be easily accessed. A database management system is an electronic filing cabinet that stores data, and also allows you to add, delete, modify an retrieve data.
Reduces Data Redundancy Improves Data Consistency Enables Data Sharing Aids Standardization Maintains Data Integrity Ensures Data Security
Marks Obtained 65 90 87 89
A Relational Database is based on the relational model. A Relational Database Management System (RDBMS) is a suite of software programs for creating, maintaining, modifying, and manipulating a relational database. It can also be used to create an application for the user to interact with the data stored in the database.
RDBMS Users
Application Programmer The application programmer writes programs that end users employ to access the database.
Database Administrator The database Administrator (DBA) is primarily concerned with creating and maintaining the database, ensuring its proper functioning, and implementing the security of the database.
Information representation Unique definition of rows Systematic treatment of Null values Guaranteed access High level Update, Insert and Delete
The ER Model
Entities
An entity is a person, place, thing, object, event, or even a concept, which can be distinctly identified. This term covers a very broad spectrum. Take, for example, a student John Wright whose enrolment number is 1.002990090212. He is enrolled for a subject named Plant Pathology, with the subject code, PPL322, at an institution called St. Edmunds College. Student, subject, and institution are all examples of entities.
The ER Model
Attributes
Each entity has a set of properties or characteristics. For Example, the order number and name of an ordered item are attributes of the entity Order, as ther define the entity. Each attribute could further have properties attached to it. For example, the order number could be assigned the Not Null and the UNIQUE properties. This Would imply that the order number is mandatory, and must be unique.
The ER Model
Relationship
A relationship can be defined as an association among entities. For example, A person has lunch at the hotel is an association between person, lunch and Hotel.
Denotes an entity in an ERD Represents an attribute of an entity Denotes the relationship between entities
Example ERD
The symbols used in the ERD are explained below:
Customer Code Customer Name Address Phone No. Order No Qty Ordered Order Date Item Code
Customer Code
Customer
Places
Order
Normalization
Rule 1 Eliminate Repeating Groups
FIRTS NORMAL FORM
Un-Normalized data items for Puppies Puppy Number Puppy Name Kennel Code Kennel Name Kennel Location Trick ID 1...N Trick Name 1... N Skill Level 1 ... N
Puppy Table Puppy number Puppy Name Kennel Code Kennel Name Kennel Location
Primary Key
Trick Table Puppy Number (Foreign Key) Primary Key Trick ID Trick Name Skill Level
Normalization
Rule 2 Eliminate Redundant Data
SECOND NORMAL FORM Puppy Table Puppy number Puppy Name Kennel Code Kennel Name Kennel Location Trick Table Trick ID Trick Name Puppy Trick Table Puppy Number Trick ID Skill Level
TRICK TABLE Puppy Trick Trick Number ID Name 52 53 54 27 16 27 Roll Over Nose Stand Roll Over
Skill Level 9 9 5
Normalization
Rule 3 Eliminate Columns not Dependent on Key
THIRD NORMAL FORM Puppy Table Puppy Number Puppy name Kennel Code Kennel Table Kennel Code Kennel Name Kennel Location Trick Table Trick ID Trick Name Puppy Trick Table Puppy Number Trick ID Skill Level
Puppy Table Puppy Number Puppy Name Kennel Code Kennel Name Kennel Location
Creating a Table
The syntax for creating a table using T-SQL is: Sintax: CREATE TABLE <Table Name> (<Column_Name> <Data_Type>) Example: CREATE TABLE Airlines_Master (Aircode CHAR(2), Airline_name VARCHAR(15) )
Modifying a Table
The syntax for modifying a table using T-SQL is: Sintax: ALTER TABLE <Table Name> [ALTER COLUMN <Column_name> <New_Data_Type>] ! ADD [<Column_name> <Data_Type>] ! DROP COLUMN [<Column_name>] Example: ALTER TABLE Airlines_Master ADD NoOfAircraft INT
Adding rows
The syntax for adding rows using T-SQL is: Sintax: INSERT [INTO] <Table Name> VALUES <values> Example: INSERT INTO Airlines_Master VALUES (AI, Airlines China, 25)
Updating rows
The syntax for updating a table using T-SQL is: Sintax: UPDATE <Table Name> SET <Column_name = Value> [WHERE <Condition>]
Example:
UPDATE Airlines_Master SET Airline_name = Air China WHERE Aircode = AI
Deleting rows
The syntax for deleting a table using T-SQL is: Sintax: DELETE FROM <Table Name> [WHERE <Condition>] Example: DELETE FROM Airlines_Master WHERE Aircode = AI
Removing a Table
Youd may need, to delete a table, if the database design changes, or the data in the table becomes obsolete. When you delete a table, its structural definition, data, full text indexes, constrainst, and indexes are permanently deleted from the database. The space fomerly used to store the table and its indexes, is made available for other tables. Sintax: DROP TABLE <Table_Name> Example: DROP TABLE Airlines_Master