Lec5 Se DB
Lec5 Se DB
SOFTWARE
ENGINEERING
DATABASE
TABLE OF CONTENTS
01 DATABASE
02 SQL
03 DBMS
INTRODUCTION
WHAT IS A DATABASE?
Organized collection of data
One thing relational DBMS share is the SQL (Structured Query Language)
DBMS
SOFTWARE TO PROCESS QUERIES
THE LOGICAL LEVEL
SOFTWARE TO ACCESS THE STORED DATA
Database schema: the logical representation of the database (like variable data type in
programming)
2. Foreign key: set a link between two tables. Enforces data integrity. It is a foreign key in one table that
references a primary key in another table and used to set relationships. This enables the use of SQL join
query to allow us pull data from two related tables (creating a view)
3. VIEWS: used to pull data out of tables, and they are secure as enables the users to pull data out of tables
without actually giving them access to tables. Simplify the output of the tables (selects only the required
col/records)
4. INDEX: put an index on col so that a query finds it quicker. Exactly like you look in a textbook. Quickly and
efficiently retrieve the data
5. Stored PROCEDURES: similar to views, container for sql code. They are stored and you can pass
parameters to it to retrieve the data.
DML
Data manipulation language
TCL
Transaction control language
DQL
Data query language
DCL
Data control language
Entity
Entity
Entity
2. Data Types:
a. Numeric data types
b. String data types
c. Date & Time data types
d. XML data type
e. Spatial data type
2. Composite Primary Key: two or more foreign keys are used as a Primary key.
One
Many
Zero to many
1 to many
Zero or 1
DML
Data manipulation language
TCL
Transaction control language
DQL
Data query language
DCL
Data control language
Used to create the database structure are known as data definition language (DDL).
SELECT: retrieves certain records from one or more tables. Considered as DQL
1. NUMERIC: bigint, int, smallint, tinyint, bit, numeric, money, smallmoney, float, real
2. STRING:
(non-Unicode) char, varchar, varchar(max), text
(Unicode) nchar, Nvarchar,nvarchar(max)
1. DATE AND TIME: date, time, datetime
FOREIGN KEY(CustomerID)
REFERENCES Customers(CustomerID),
CustomerName varchar(100),
To_Street varchar(50),
To_City varchar(50),
To_ZipCode varchar(50),
ShippingDate datetime,
OrderDate datetime,
ProductID int,
);
EX.
CREATE TABLE administrators (LIKE Customers);
SELECT * SELECT *
FROM table_name; FROM Customers;
WHERE condition;
RETURNING *;
EX
UPDATE Customers
SET Firstname=‘Jo’
WHERE CustomerID=1;
IF YOU DON’T USE A WHERE CLAUSE, YOU WILL UPDATE ALL THE DATA IN
TABLE
If you don’t use a where condition, all the data in the table will be deleted.
01 DBMS
02 ERD
03 SQL