Chapter 1

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 26

IMPLEMENTING RDBMS CONCEPTS WITH SQL SERVER 2005

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.

Evolution of the DBMS A Historical Perspective

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.

What is a Database Management System?

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.

Benefits of a Database System


Reduces Data Redundancy Improves Data Consistency Enables Data Sharing Aids Standardization Maintains Data Integrity Ensures Data Security

Relational Data Model


Roll Number Student Name 2 John 4 Lisa 7 Joe 1 Sam 5 Penny 3 Jenny 6 Peter
Roll Number Marks Obtained 3 45 6 65 4 90 1 34 2 87 7 89 5 36

Roll Number Student Name 6 Peter 4 Lisa 2 John 7 Joe

Marks Obtained 65 90 87 89

What is a Relational Database Management System?

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

RDBMS users are of three categories.


End User The end user invokes an application to interact with the system, or writes a query for easy retrieval, modification, or deletion of data.

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.

Relational Features of SQL Server


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.

Entity Relationship Diagram (ERD)


The symbols used in the ERD are explained below: Symbol Description

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

Viewing the Table


After you have created the tables in a database, you may need to find information about the table properties (for example, the name or data type of a column, the nature of its indexes, etc.) Sintax: sp_help <Table Name> Example: sp_help Airlines_Master

Viewing the Table


Additionally, and most importantly, you can view the data in a table. Sintax: SELECT <Select_list> FROM <Table_Name> Example: SELECT * FROM Airlines_Master The asterisk (*) in the above example specifies that all columns of the table should be displayed. To view specific columns , you have to specify the column names, separated by commas.

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

You might also like