2. What is a databaseWhat is a database
A database is any organized collection ofA database is any organized collection of
data.data. Some examples of databases youSome examples of databases you
may encounter in your daily life are:may encounter in your daily life are:
a telephone booka telephone book
airline reservation systemairline reservation system
motor vehicle registration recordsmotor vehicle registration records
files on your computer hard drivefiles on your computer hard drive
Employment recordsEmployment records
3. Data vs. information:Data vs. information:
What is the difference?What is the difference?
What is data?What is data?
Raw Facts and Figures.Raw Facts and Figures.
Information science definesInformation science defines
data as unprocesseddata as unprocessed
information.information.
What is information?What is information?
Information is data thatInformation is data that
have been organized andhave been organized and
communicated in acommunicated in a
coherent and meaningfulcoherent and meaningful
manner.manner.
Data is converted intoData is converted into
information, andinformation, and
information is convertedinformation is converted
into knowledge.into knowledge.
Knowledge; informationKnowledge; information
evaluated and organizedevaluated and organized
so that it can be usedso that it can be used
purposefully.purposefully.
4. Why do we need a database?Why do we need a database?
Keep records of our:Keep records of our:
ClientsClients
StaffStaff
Keep sales records;Keep sales records;
Develop reports;Develop reports;
Perform researchPerform research
5. What is the ultimate purpose ofWhat is the ultimate purpose of
a database managementa database management
system?system?
DataData InformationInformation KnowledgeKnowledge ActionAction
Is to transformIs to transform
6. Database management systemsDatabase management systems
(DBMS)(DBMS)
collections of tools used to manage databasescollections of tools used to manage databases
Basic functions performed by all DBMS are:Basic functions performed by all DBMS are:
Create, modify, and delete data structures,Create, modify, and delete data structures,
e.g. tablese.g. tables
Add, modify, and delete dataAdd, modify, and delete data
Retrieve data selectivelyRetrieve data selectively
Generate reports based on dataGenerate reports based on data
7. Database ModelsDatabase Models
a number of different ways of modeling thea number of different ways of modeling the
database structure: these are known asdatabase structure: these are known as
“database models” (or data models).“database models” (or data models).
The model in most common use today isThe model in most common use today is
thethe relational model, which in layman'srelational model, which in layman's
terms represents allterms represents all information in theinformation in the
form of multiple related tables eachform of multiple related tables each
consisting of rows and columnsconsisting of rows and columns
9. TablesTables
A table is a collection of related records. ForA table is a collection of related records. For
example, employee table, product table,example, employee table, product table,
customer, and orders tablescustomer, and orders tables
In a table, records are represented by rows andIn a table, records are represented by rows and
fields are represented as columns.fields are represented as columns.
10. FieldsFields
An area (within a record) reserved for a specific piece ofAn area (within a record) reserved for a specific piece of
datadata
Examples: customer id, customer name, street address,Examples: customer id, customer name, street address,
city, phone, current balancecity, phone, current balance
defined by:defined by:
Field nameField name
Data typeData type
Field size (Field size (Amount of space reserved for storing dataAmount of space reserved for storing data ))
11. RecordRecord
A record is the collection of values for allA record is the collection of values for all
the fields belong to one entity: i.e. athe fields belong to one entity: i.e. a
person, product, company, transaction,person, product, company, transaction,
etc.etc.
Key field column(DOB is field)Key field column(DOB is field)
recordrecord Customer No Name DOB
…… …… …….
1234 Bilal 10/10/1990
13. RelationshipsRelationships
One-to-Many relationship:One-to-Many relationship: Customer-Order, each order has onlyCustomer-Order, each order has only
one customer, but a customer can make many ordersone customer, but a customer can make many orders
One-to-Many relationships consist of two tables, the "one" table, andOne-to-Many relationships consist of two tables, the "one" table, and
the "many“ tablesthe "many“ tables
CustomerCustomer
OrderOrder
1 m1 m
14. RelationshipsRelationships
Many-to-Many relationship: Order-Product, an orderMany-to-Many relationship: Order-Product, an order
can contain many products,can contain many products, and a product can be onand a product can be on
many ordersmany orders
A Many-to-Many relationship consists of three tables:A Many-to-Many relationship consists of three tables:
two "one" tables, both in a One-to-Many relationship withtwo "one" tables, both in a One-to-Many relationship with
a third table. The third table is sometimes referred to asa third table. The third table is sometimes referred to as
the lienthe lien
Product OrderProduct Order
m nm n
15. Key FieldsKey Fields
Primary key:Primary key: A Primary key is a field or a combination of twoA Primary key is a field or a combination of two
or moreor more fields. Thefields. The value in the primary key field for each recordvalue in the primary key field for each record
uniquely identifies that recorduniquely identifies that record
In our previous example, customer number is the Primary key forIn our previous example, customer number is the Primary key for
the Customer table. A customer number identifies one and only onethe Customer table. A customer number identifies one and only one
customer in the Customer tablecustomer in the Customer table
Foreign key: When a "one" table's primary key field is added toForeign key: When a "one" table's primary key field is added to
aa related "many" table in order to create the common field whichrelated "many" table in order to create the common field which
relates the two tables, it is called a foreign key in the "many" table.relates the two tables, it is called a foreign key in the "many" table.
the primary key (customer number) from the Customer table ("one"the primary key (customer number) from the Customer table ("one"
table) is a foreign key in the Orders table ("many" table). For thetable) is a foreign key in the Orders table ("many" table). For the
"many" records of the Order table, the foreign key identifies with"many" records of the Order table, the foreign key identifies with
which unique record in the Customer table they are associated.which unique record in the Customer table they are associated.
16. Data TypesData Types
This will hold between 0 and 255 characters. You have to specifyThis will hold between 0 and 255 characters. You have to specify
the maximum amount of characters that you will be putting herethe maximum amount of characters that you will be putting here
when you create your columnwhen you create your column
This will hold as many characters as you like up to 2 gigabytes ofThis will hold as many characters as you like up to 2 gigabytes of
spacespace
This can hold a value of 0 or 1. It is primarily used for yes/no andThis can hold a value of 0 or 1. It is primarily used for yes/no and
true/false issues. It is also referred to as a Boolean or Yes/Notrue/false issues. It is also referred to as a Boolean or Yes/No
field.field.
This type is used to store decimal numbers. It is primarily used forThis type is used to store decimal numbers. It is primarily used for
mathematical purposesmathematical purposes
This type indicates that you are storing whole numbers here. YouThis type indicates that you are storing whole numbers here. You
can store any whole number between -2147483648 andcan store any whole number between -2147483648 and
21474836482147483648
● CHARCHAR
VARCHARVARCHAR
BITBIT
FLOATFLOAT
INTINT
17. How Do I Create a Table?How Do I Create a Table?
Using an SQL statement.Using an SQL statement.
CREATE TABLE contacts (CREATE TABLE contacts (
contact_id INT IDENTITY (1, 1) NOT NULL ,contact_id INT IDENTITY (1, 1) NOT NULL ,
first_name CHAR (30) NULL ,first_name CHAR (30) NULL ,
last_name CHAR (50) NULL ,last_name CHAR (50) NULL ,
email VARCHAR (75) NULLemail VARCHAR (75) NULL
););
18. Designing a Table in a DatabaseDesigning a Table in a Database
Tool? ….Tool? ….
Using Microsoft AccessUsing Microsoft Access
19. INSERT statementINSERT statement
INSERT INTO contactsINSERT INTO contacts
(first_name, last_name, email)(first_name, last_name, email)
VALUES (‘Bilal',‘Afzal',‘bilal@hotmail.com’);VALUES (‘Bilal',‘Afzal',‘bilal@hotmail.com’);
20. What is thatWhat is that NULL thing?NULL thing?
NULL is how you tell the DBMS that you have nothing toNULL is how you tell the DBMS that you have nothing to
enter in this columnenter in this column
24. Example QueriesExample Queries
AND/OR operatorsAND/OR operators
SELECT * FROM contacts WHERE(first_name=‘Bilal'SELECT * FROM contacts WHERE(first_name=‘Bilal' ANDAND
last_name=‘Afzal')last_name=‘Afzal') OR last_name=‘Ahmed';OR last_name=‘Ahmed';
LIKELIKE
SELECT * FROM contact WHERE last_nameSELECT * FROM contact WHERE last_name LIKE '%al';LIKE '%al';
ORDER BY Clause:ORDER BY Clause:
SELECT * FROM contacts ORDER BY last_nameSELECT * FROM contacts ORDER BY last_name DESC;DESC;