+ All Categories
Home > Education > Database

Database

Date post: 25-Jan-2017
Category:
Upload: determinant342
View: 221 times
Download: 0 times
Share this document with a friend
25
Database Basics Database Basics By: By: Muhammad Nawaz Muhammad Nawaz
Transcript
Page 1: Database

Database BasicsDatabase Basics

By: Muhammad NawazBy: Muhammad Nawaz

Page 2: Database

What is a databaseWhat is a database

A database is any organized collection of A database is any organized collection of data.data. Some examples of databases you Some examples of databases you may encounter in your daily life are: may encounter in your daily life are: a telephone book a telephone book airline reservation system airline reservation system motor vehicle registration records motor vehicle registration records files on your computer hard drivefiles on your computer hard drive Employment records  Employment records 

Page 3: Database

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 defines Information science defines data as unprocessed data as unprocessed information.information.

What is information?What is information? Information is data that have Information is data that have

been organized and been organized and communicated in a coherent communicated in a coherent and meaningful manner. and meaningful manner.

Data is converted into Data is converted into information, and information information, and information is converted into knowledge.is converted into knowledge.

Knowledge; information Knowledge; information evaluated and organized so evaluated and organized so that it can be used that it can be used purposefully.purposefully.

Page 4: Database

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

Page 5: Database

What is the ultimate purpose of What is the ultimate purpose of a database management a database management

system?system?

Data Information Knowledge Action

Is to transformIs to transform

Page 6: Database

Database management systems Database 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

Page 7: Database

Database ModelsDatabase Models

a number of different ways of modeling the a number of different ways of modeling the database structure: these are known as database structure: these are known as “database models” (or data models).“database models” (or data models).The model in most common use today is The model in most common use today is the the relational model, which in layman's relational model, which in layman's terms represents all terms represents all information in the information in the form of multiple related tables each form of multiple related tables each consisting of rows and columnsconsisting of rows and columns

Page 8: Database

Databases ComponentsDatabases Components

Related tables/RelationsRelated tables/Relations FieldsFields RecordsRecords

Page 9: Database

TablesTables

A table is a collection of related records. For A table is a collection of related records. For example, employee table, product table, example, employee table, product table, customer, and orders tablescustomer, and orders tablesIn a table, records are represented by rows and In a table, records are represented by rows and fields are represented as columns.fields are represented as columns.

Page 10: Database

FieldsFieldsAn area (within a record) reserved for a specific piece of An area (within a record) reserved for a specific piece of datadataExamples: 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 nameData typeData typeField size (Field size (Amount of space reserved for storing data Amount of space reserved for storing data ))

Page 11: Database

RecordRecord

A record is the collection of values for all A record is the collection of values for all the fields belong to one entity: i.e. a the 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

Page 12: Database

One-to-OneOne-to-One One-to-ManyOne-to-Many Many-to-ManyMany-to-Many

RelationshipsRelationships

Page 13: Database

RelationshipsRelationshipsOne-to-Many relationship: One-to-Many relationship: Customer-Order, each order has only Customer-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, and One-to-Many relationships consist of two tables, the "one" table, and the "many“ tablesthe "many“ tables

Customer Customer OrderOrder

1 m1 m

Page 14: Database

RelationshipsRelationshipsMany-to-Many relationship: Order-Product, an order Many-to-Many relationship: Order-Product, an order can contain many products, can contain many products, and a product can be on and a product can be on many ordersmany ordersA 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 with two "one" tables, both in a One-to-Many relationship with a third table. The third table is sometimes referred to as a third table. The third table is sometimes referred to as the lienthe lien

Product OrderProduct Order m nm n

Page 15: Database

Key FieldsKey Fields

Primary key: Primary key: A Primary key is a field or a combination of two A Primary key is a field or a combination of two or more or more fields. The fields. The value in the primary key field for each record value in the primary key field for each record uniquely identifies that recorduniquely identifies that recordIn our previous example, customer number is the Primary key for In our previous example, customer number is the Primary key for the Customer table. A customer number identifies one and only one the Customer table. A customer number identifies one and only one customer in the Customer tablecustomer in the Customer tableForeign key: When a "one" table's primary key field is added to Foreign key: When a "one" table's primary key field is added to a a related "many" table in order to create the common field which related "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 the table) 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.

Page 16: Database

Data TypesData TypesThis will hold between 0 and 255 characters. You have to specify This will hold between 0 and 255 characters. You have to specify the maximum amount of characters that you will be putting here the maximum amount of characters that you will be putting here when you create your columnwhen you create your columnThis will hold as many characters as you like up to 2 gigabytes of This will hold as many characters as you like up to 2 gigabytes of spacespaceThis can hold a value of 0 or 1. It is primarily used for yes/no and This 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/No true/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 for This type is used to store decimal numbers. It is primarily used for mathematical purposesmathematical purposesThis type indicates that you are storing whole numbers here. You This type indicates that you are storing whole numbers here. You can store any whole number between -2147483648 and can store any whole number between -2147483648 and 21474836482147483648

● CHARCHAR

VARCHARVARCHAR

BITBIT

FLOATFLOAT

INTINT

Page 17: Database

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););

Page 18: Database

Designing a Table in a Database Designing a Table in a Database Tool? ….Tool? ….

Using Microsoft AccessUsing Microsoft Access

Page 19: Database

INSERT statementINSERT statement

INSERT INTO contactsINSERT INTO contacts (first_name, last_name, email)(first_name, last_name, email) VALUES (‘Bilal',‘Afzal',‘[email protected]’);VALUES (‘Bilal',‘Afzal',‘[email protected]’);

Page 20: Database

What is that What is that NULL thing?NULL thing?

NULL is how you tell the DBMS that you have nothing to NULL is how you tell the DBMS that you have nothing to enter in this columnenter in this column

Page 21: Database

UPDATE StatementUPDATE Statement

UPDATE contactsUPDATE contacts SETSET email = ‘[email protected]‘email = ‘[email protected]‘ WHEREWHERE contact_id = 1;contact_id = 1;

Page 22: Database

SELECT StatementSELECT Statement

SELECT * FROM contacts;SELECT * FROM contacts;SELECT first_name, emailSELECT first_name, email

FROMFROM contactscontacts WHEREWHERE first_name = ‘Bilal';first_name = ‘Bilal';

Page 23: Database

DELETE statementDELETE statement

DELETEDELETE FROM contactsFROM contacts WHERE contact_id = 3;WHERE contact_id = 3;

Page 24: Database

Example QueriesExample Queries

AND/OR operatorsAND/OR operatorsSELECT * FROM contacts WHERE(first_name=‘Bilal' SELECT * FROM contacts WHERE(first_name=‘Bilal' AND AND last_name=‘Afzal') last_name=‘Afzal') OR last_name=‘Ahmed'; OR last_name=‘Ahmed';

LIKELIKESELECT * FROM contact WHERE last_name SELECT * FROM contact WHERE last_name LIKE '%al';LIKE '%al';

ORDER BY Clause:ORDER BY Clause:SELECT * FROM contacts ORDER BY last_name SELECT * FROM contacts ORDER BY last_name DESC;DESC;

Page 25: Database

ThanksThanks


Recommended