DBMS

Designing Steps

a

Conceptual Designning

ER

r

Entity relationship model defines the conceptual view of database.It works around real world entity and association among them. At view level, ER model is considered well for designing databases.

Entity

Strong

Weak

Attributes

Simple

r

Simple attributes are atomic values, which cannot be divided further.

Composite

r

Composite attributes are made of more than one simple attribute.

Multi-Value

r

Multi-value attribute may contain more than one values.

Complex

Base / Derived

r

Derived attributes are attributes, which do not exist physical in the database, but there values are derived from other attributes presented in the database.

Keys

r

Key is an attribute or collection of attributes that uniquely identifies an entity among entity set.

Super Key

r

Set of attributes (one or more) that collectively identifies an entity in an entity set.

Candidate / Alternate Key

r

Minimal super key is called candidate key that is, supers keys for which no proper subset are a superkey.An entity set may have more than one candidate key.

Primary key

r

This is one of the candidate key chosen by the database designer to uniquely identify the entity set.

Foreign Key

Composite key

Relationships

Unary / Recursive

Binary

Complex - Ternary

Relationships Constraints

Cardinality

r

Cardinality defines the number of entities in one entity set which can be associated to the number of entities of other set via relationship set.

1:1

1 : m

m : n

Partcipations

Total

Partial

E-ER

r

* Subclass / Superclass * Generalization / Specialization,* Categories(union) * Attribute & relationship inheritance

Rule 8

r

* Subclass / Superclass

Option A

r

Disjoint Participation :Create Super Entity TableCreate every Sub class Entity with super class Primary key

Option B

r

Total Participation :​​​Create every Sub Class as a entity with Super Class Primary Key & Super class attributes

Option C

r

Create 1 table for Whole Super Class Sub Class Relationship

Option D

r

Create 1 table for Whole Super Class Sub Class RelationshipWith Flag values

Rule 9

Mapping of Unions

Specilaization

Logical Designning

E-ER

Physical Designing

Mapping

Normalization

r

* Functional Dependencies EmpNum --> EmpEmail* Determinant Attribute on the LHS is known as the*

Defendancy

Functional Dependency

r

* Functional Dependencies EmpNum --> EmpEmail

Determinant

r

* Determinant Attribute on the LHS is known as theEmpNum --> EmpEmail

Full Functional Dependency

Partial Dependency

Transitive Dependency

1NF

r

This is defined in the definition of relations (tables) itself. This rule defines that all the attributes in a relation must have atomic domains.Values in atomic domain are indivisible units.* Each attribute must contain only single value from its pre-defined domain.

2NF

r

* Second normal form says, that every non-prime attribute should be fully functionally dependent on prime key attribute.Prime/Key attribute : an attribute, which is part of prime-key, is prime attribute.Non-prime/key attribute: an attribute, which is not a part of prime-key, is said to be a non-prime attribute.

3NF

r

For a relation to be in Third Normal Form, it must be in Second Normal form and the following must satisfy:

BCNF

4NF

5NF

SQL

SQL Constarints

Not Null

Unique

Primary Key

Foreign Key

r

A FOREIGN KEY in one table points to a PRIMARY KEY in another table.MySQL:CREATE TABLE Orders (O_Id int NOT NULL,OrderNo int NOT NULL,P_Id int,PRIMARY KEY (O_Id),FOREIGN KEY (P_Id) REFERENCES Persons(P_Id))SQL Server / Oracle / MS Access:CREATE TABLE Orders (O_Id int NOT NULL PRIMARY KEY,OrderNo int NOT NULL,P_Id int FOREIGN KEY REFERENCES Persons(P_Id))

Check

Default

r

The DEFAULT constraint is used to insert a default value into a column.The default value will be added to all new records, if no other value is specified.

Commands

DDL

r

Data definition Languageused to create and modify the structure of database objects in database

CREATE

r

Creates objects in the database

ALTER

r

Alters objects of the database

DROP

r

Deletes objects of the database

TRUNCATE

r

Deletes all records from a table and resets table identity to initial value.

Rename

DML

r

Data Manipulation LanguageDML modifies the database instance by inserting, updating and deleting its data. DML is responsible for all data modification in databases

SELECT

r

Retrieves data from a table

INSERT

r

Inserts data into a table

UPDATE

r

Updates existing records into a tableUPDATE table_nameSET column1=value1,column2=value2,...WHERE some_column=some_value;

DELETE

r

Deletes dat records from a table

Subtopic

TCL

r

Transactional Control Languageused to manage different transactions occurring within a database

a

COMMIT

r

Saves work done in transactions

ROLLBACK

r

Restores database to original state since the last COMMIT command in transactions

SAVE TRANSACTION

r

Sets a savepoint within a transaction

DCL

r

Data Control LanguageFor database authorization, role control operationused to control access to database by securing it.

GRANT

r

Gives user’s access privileges to database

REVOKE

r

Withdraws user’s access privileges to database given with the GRANT command

Other

SELECT DISTINCT

r

In a table, a column may contain many duplicate values; and sometimes you only want to list the different (distinct) values.The DISTINCT keyword can be used to return only distinct (different) values.

WHERE

r

The WHERE clause is used to filter records.The WHERE clause is used to extract only those records that fulfill a specified criterion.

IN

r

The IN operator allows you to specify multiple values in a WHERE clause.SELECT * FROM CustomersWHERE City IN ('Paris','London');

BETWEEN

r

The BETWEEN operator is used to select values within a range.The values can be numbers, text, or dates.SELECT * FROM ProductsWHERE Price NOT BETWEEN 10 AND 20;

LIKE

r

The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.SELECT * FROM CustomersWHERE City LIKE '%s';

Wildcards

r

A wildcard character can be used to substitute for any other character(s) in a string.In SQL, wildcard characters are used with the SQL LIKE operator.SQL wildcards are used to search for data within a table. 

%

r

A substitute for zero or more charactersSELECT * FROM CustomersWHERE City LIKE '%es%';

_

r

A substitute for a single characterSELECT * FROM CustomersWHERE City LIKE 'L_n_on';

[charlist]

r

Sets and ranges of characters to matchSELECT * FROM CustomersWHERE City LIKE '[bsp]%';

[^charlist]
or
[!charlist]

r

Matches only a character NOT specified within the bracketsSELECT * FROM CustomersWHERE City LIKE '[!bsp]%';orSELECT * FROM CustomersWHERE City NOT LIKE '[bsp]%';

AND & OR

r

The AND & OR operators are used to filter records based on more than one condition.The AND operator displays a record if both the first condition AND the second condition are true.The OR operator displays a record if either the first condition OR the second condition is true.

ORDER BY

r

The ORDER BY keyword is used to sort the result-set.The ORDER BY keyword is used to sort the result-set by one or more columns.The ORDER BY keyword sorts the records in ascending order by default.To sort the records in a descending order, you can use the DESC keyword.

SELECT TOP

r

The SELECT TOP clause is used to specify the number of records to return.The SELECT TOP clause can be very useful on large tables with thousands of records. Returning a large number of records can impact on performance.Note: Not all database systems support the SELECT TOP clause.SELECT TOP number|percent column_name(s)FROM table_name;SELECT TOP 2 * FROM Customers;SELECT TOP 50 PERCENT * FROM Customers;

Aliases

r

SQL aliases are used to temporarily rename a table or a column heading.SQL aliases are used to give a database table, or a column in a table, a temporary name.Basically aliases are created to make column names more readable.

SELECT INTO

r

With SQL, you can copy information from one table into another.The SELECT INTO statement copies data from one table and inserts it into a new table.

INSERT INTO SELECT

r

With SQL, you can copy information from one table into another.The INSERT INTO SELECT statement copies data from one table and inserts it into an existing table.

CREATE INDEX

r

An index can be created in a table to find data more quickly and efficiently.The users cannot see the indexes, they are just used to speed up searches/queries.Note: Updating a table with indexes takes more time than updating a table without (because the indexes also need an update). So you should only create indexes on columns (and tables) that will be frequently searched against.

AUTO INCREMENT

r

Very often we would like the value of the primary key field to be created automatically every time a new record is inserted.We would like to create an auto-increment field in a table.

Joins

r

An SQL JOIN clause is used to combine rows from two or more tables,based on a common field between them.The most common type of join is: SQL INNER JOIN (simple join). An SQL INNER JOIN return all rows from multiple tables where the join condition is met.

INNER JOIN

r

The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns in both tables.SELECT column_name(s)FROM table1INNER JOIN table2ON table1.column_name=table2.column_name;SELECT Customers.CustomerName, Orders.OrderIDFROM CustomersINNER JOIN OrdersON Customers.CustomerID=Orders.CustomerIDORDER BY Customers.CustomerName;

LEFT JOIN

LEFT JOIN

r

The LEFT JOIN keyword returns all rows from the left table (table1), with the matching rows in the right table (table2).The result is NULL in the right side when there is no match.PS! In some databases LEFT JOIN is called LEFT OUTER JOIN.SELECT column_name(s)FROM table1LEFT OUTER JOIN table2ON table1.column_name=table2.column_name;

RIGHT JOIN

r

The RIGHT JOIN keyword returns all rows from the right table (table2), with the matching rows in the left table (table1).The result is NULL in the left side when there is no match.SELECT column_name(s)FROM table1RIGHT JOIN table2ON table1.column_name=table2.column_name;

FULL OUTER JOIN

r

The FULL OUTER JOIN keyword returns all rows from the left table (table1) and from the right table (table2).The FULL OUTER JOIN keyword combines the result of both LEFT and RIGHT joins.SELECT column_name(s)FROM table1FULL OUTER JOIN table2ON table1.column_name=table2.column_name;

UNION

r

The UNION operator is used to combine the result-set of two or more SELECT statements.Notice that each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order.SELECT column_name(s) FROM table1UNIONSELECT column_name(s) FROM table2;

Views

r

In SQL, a view is a virtual table based on the result-set of an SQL statement.A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database.You can add SQL functions, WHERE, and JOIN statements to a view and present the data as if the data were coming from one single tableNote: A view always shows up-to-date data! The database engine recreates the data, using the view's SQL statement, every time a user queries a view.

Create

r

CREATE VIEW view_name ASSELECT column_name(s)FROM table_nameWHERE conditionCREATE VIEW [Products Above Average Price] ASSELECT ProductName,UnitPriceFROM ProductsWHERE UnitPrice>(SELECT AVG(UnitPrice) FROM Products)

Update

r

CREATE OR REPLACE VIEW view_name ASSELECT column_name(s)FROM table_nameWHERE conditionCREATE VIEW [Current Product List] ASSELECT ProductID,ProductName,CategoryFROM ProductsWHERE Discontinued=No

Delete

r

DROP VIEW view_name

Triggers

Functions

r

SQL has many built-in functions for performing calculations on data.

Aggregate Functions

r

SQL aggregate functions return a single value, calculated from values in a column.

AVG()

r

Returns the average value of a numeric column.SELECT AVG(column_name) FROM table_nameSELECT ProductName AS Pr-name, Price FROM ProductsWHERE Price > (SELECT AVG(Price) FROM Products);

COUNT()

r

Returns the number of rows that matches a specified criteria.SELECT COUNT(column_name) FROM table_name;SELECT COUNT(CustomerID) AS OrdersFromCustomerID7 FROM OrdersWHERE CustomerID=7;

FIRST()

r

Returns the first value

LAST()

r

Returns the last value

MAX()

r

Returns the largest value

MIN()

r

Returns the smallest value

SUM()

r

Returns the total sum of a numeric column.SELECT SUM(column_name) FROM table_name;SELECT SUM(Quantity) AS TotalItemsOrdered FROM OrderDetails;

Scalar functions

r

SQL scalar functions return a single value, based on the input value.

UCASE()

r

Converts a field to upper case

LCASE()

r

Converts a field to lower case

MID()

r

Extract characters from a text field

LEN()

r

Returns the length of a text field

ROUND()

r

Rounds a numeric field to the number of decimals specified

NOW()

r

Returns the current system date and time

FORMAT()

r

Formats how a field is to be displayed

Related Topics

SQL Injection

r

An SQL Injection can destroy your database.SQL injection is a technique where malicious users can inject SQL commands into an SQL statement, via web page input.Injected SQL commands can alter SQL statement and compromise the security of a web application.

Mapping Rules

Rule 1

Map Strong Entity

Rule 2

Map weak Entity

Rule 3

Map Multi-Value Attributes

Rule 4

Map 1:1 Relations

Rule 5

Map 1:m Relations

Rule 6

Map m:n Relations

Rule 7

Map Turnary Relations

Normalization Digram

Normalization Digram