You are on page 1of 19

Introduction to Database

Database Management Systems


Instructor: Maryam Munawar
Outline
• Database Design
• Storage Manager
• Query Processing
• Transaction Manager
Logical Database Design
• The logical database design contains the
definition of the data to be stored in
database. It also contains the rules and
information about the structure and type
of data. All entities, their relationships
are describe in logical model.
• Logical Database Design Process
Logical Database Design Process
• Represent Entities
•Each entity in a E R diagram is represented as a relation in relational model. In this
process, the name of entity becomes the name of relation. The indetifier of entity type
becomes the primary key of relation. The remaining attributes of the entity type become no-
key attribute of the relation.
• Represent Relationship
• Merge the Relations/View integration (Redundant Relation (Two or
more relations describe the same entity type))
• Normalize the Relation
Physical Database Design
• The major objective of physical database design is to implement the
database as a set of records, files, indexes and other data structure.
• Major Input of Database Design
• Logical database stucture (normalized relations)
• User processing requirements (database usage, response time, security, backup, and
recover etc. )
• Characteristics of DBMS
Database Design
Data Definiton and Modifictaion
• Create Table • Example
• The CREATE TABLE statement is CREATE TABLE EMP
used to create a new table.
(EMPNO NUMBER(4),
• Syntax
ENAME VARCHAR(30),
CREATE TABLE table_name
JOB VARCHAR(15),
(column1 data type, column2 data type)
MGR NUMBER(4),
SAL NUMBER(7,2),
COMM NUMBER(7,2),
DEPTNO NUMBER (4));
Data Definiton and Modifictaion
• Altering an Existing Table • Example
• The ALTER TABLE statement is used to • ALTER TABLE EMP
add or drop columns in an existing table. • ADD CITY VARCHAR (30);
• ALTER TABLE table_name
• ADD column_name datatype; • ALTER TABLE EMP
• ALTER TABLE table_name • DROP CITY;
• DROP column_name;
• ALTER TABLE table_name
• ALTER TABLE EMP
• MODIFY column_name datatype;
• MODIFY CITY CHAR(25));
Data Definiton and Modifictaion
• Deleting a Table
• The DROP statement is used to delete a table along with table structure,
attributes and indexes
• Syntax
• DROP TABLE table_name;
• Example
• DROP TABLE EMP;
Data Definiton and Modifictaion
• Truncating a Table
• The TRUNCATE TABLE statement is used to delete all data in a table. It
does not delete the table structure.
• Syntax
• TRUNCATE TABLE table_name
• Example
• TRUNCATE TABLE EMP;
Constraints
• A property that can be set on a column or set of coulmns in a table is called constraint.
• Types of Contraints
• NULL/NOT NULL
• UNIQUE
• PRIMARY KEY
• FOREIGN KEY
• CHECK Constraint
• Adding or Dropping a Constraint
NULL/ NOT NULL
• It determines whether a column can be blank or not.
• Example
CREATE TABLE EMP
(EMPNO NUMBER(4) NOT NULL,
ENAME VARCHAR(30) NOT NULL,
JOB VARCHAR(15),
MGR NUMBER(4),
SAL NUMBER(7,2),
COMM NUMBER(7,2),
DEPTNO NUMBER (4) NOT NULL);
UNIQUE
• A UNIQUE constraint specifies that all values in a given column must be
unique
• Example
CREATE TABLE DEPT
(DEPTNO NUMBER (5) CONSTRAINT enum_ukey UNIQE,
DNAME VARCHAR (14),
LOC VARCHAR (13));
PRIMARY KEY
• It restricts duplication of rows and does not allow NULL value.
• Example
CREATE TABLE DEPT
(DEPTNO NUMBER (5) PRIMARY KEY,
DNAME VARCHAR (14) CONSTRAINT enum_ukey UNIQE,
LOC VARCHAR (13));
FOREIGN KEY
• Foreign key is used to create a link between the data in • Example
two tables.
CREATE TABLE EMP
• Example
(EMPNO NUMBER(4) NOT NULL,
CREATE TABLE EMP
ENAME VARCHAR(30) NOT NULL,
(EMPNO NUMBER(4) NOT NULL,
JOB VARCHAR(15),
ENAME VARCHAR(30) NOT NULL,
MGR NUMBER(4),
JOB VARCHAR(15),
SAL NUMBER(7,2),
MGR NUMBER(4),
COMM NUMBER(7,2),
SAL NUMBER(7,2),
DEPTNO NUMBER (4),
COMM NUMBER(7,2),
CONSTRAINT EMP_DEP_FK FOREIGN KEY
DEPTNO NUMBER (4) REFERENCES DEPT); (DEPTNO) REFERENCES DEPT(DEPTNO));
CHECK Constraint
• The check contraint is used to apply a test on data values in a column.
• Example
CREATE TABLE EMP
(EMPNO NUMBER (10),
NAME CHAR(20),
DEPTNO NUMBER (2),
SALARY NUMBER(7,2) CHECK (SALARY<100000));
Data Manipulation Language
• The INSERT INTO Statement
• Syntax
• INSERT INTO table_name
• VALUES (value1, value2, value3, ...);
• Example
• INSERT INTO Customers (CustomerName, ContactName, Address, City,
PostalCode, Country)
• VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');
The Update Statement
• Syntax • Example
• UPDATE table_name
• UPDATE EMP
• SET column1 = value1, column2 = value2,
... • SET JOB = ‘SALESMAN’,
• WHERE condition; ENAME = ‘CLERK’
• Example • WHERE ENAME = ‘SMITH’
• UPDATE EMP
• SET DEPTNO = 70
• WHERE ENAME = ‘SMITH’
The SQL DELETE Statement
• The DELETE statement is used to delete existing records in a table.
• Syntax
• DELETE FROM table_name WHERE condition;
• Example
• DELETE EMP
• WHERE ENAME = ‘SMITH’

You might also like