12 DBMS
12 DBMS
Collection of logically related data that has been recorded, organized and made
available for searching is called Database.
Properties of database
Banking
Online shopping
Payroll
Inventory management
Loan and investment
Reservation system And many more
What are the needs for a database?
Self Describing: DBMS not only contains the database but also the
description of the data that it stores.
Insulation between program and data: program can access data
uninterruptedly even when structure of data stored in DBMS is
modified.
Data Sharing: DBMS includes concurrency control software to allow
simultaneous access of data in the database without any inconsistency
problems.
Backup and Recovery: DBMS has provision of Backup and recovery
of data that helps user to protect the data from damage or loss.
What are different types of users of DBMS?
End users: users who use database for retrieving, updating and
creating reports as per requirement.
Database Administrator (DBA): DBA is responsible for granting data
access permission to user at different level, monitoring database usage
and provide technical support.
Application Programmer: One who write programs to create
application to interact with database. Application programmer uses
high level languages and SQL to do so.
System Analyst: they determine and specify user requirements that
help in designing efficient and reliable database.
What are the advantages of DBMS approach?
What is RDBMS?
Relation: a table is called relation. Another way we can say that collection of tuple
is called relation.
Tuple: A row of table is called tuple. In another way we can say that a single
record is called tuple
Domain: the data type of values in each column is called the Domain.
Degree: The total number of attributes in a relation is called the Degree of relation.
Relation State: the current status of a relation in terms of total numbers of tuples
at a time.
Constraints are restrictions that when applied ensure accuracy, validity and
reliability of data in a database.
What are types of constraints in RDBMS?
Domain constraint: it specifies that the value in every attribute in each tuple must
be from the domain of that attribute.
Super Key: this is a set of attribute in a relation, for which no two tuples in a
relation state have the same combination of values.
Primary Key: one of the candidate key is designated as primary key. Primary key
is used to identify tuples in relation. only one candidate key can become primary
key.
Null Value Constraints: sometimes an attribute can not have null values. That
attribute can constrained to be Not Null.
Entity Integrity Constraint: it ensures that all tuples are unique in a table.
Primary key implements entity integrity constraint.
All SQL commands are categorized in two types i.e. Data Definition Language
(DDL) and Data Manipulation language (DML) where DDL is used to define
structure and constraints of data and DML is used to insert, modify and delete data
in a database.
Decimal(m,d Fixed point number. M denotes no of digits stored for Decimal(3,2): 34.89
) values and d denotes no of decimal points. Decimal(4): 2813
Syntax:
Example:
Screenshot:
Sometimes an attribute may not be allowed to leave blank. Hence Not Null
constraints can be associated in this case.
Example:
Screenshot:
Default Constraint
Screenshot:
Check Constraint
In order to restrict the values of an attribute within a range, CHECK constraint may
be used.
CREATE TABLE EMPLOYEE
(
Emp_ID INTEGER,
Emp_NameVARCHAR(20) NOT NULL,
Gender CHAR(1),
Date_of_Birth DATE,
Salary FLOAT,
Dept varchar(20) CHECK (Dept IN (‘Store’, ‘Operation’, ‘Maintenance’)
);
Screenshot:
Primary Key
Example:
Create Order
(
Ono int Primary Key,
Odate date,
Itemno int,
Qty int,
Total int,
FOREIGN KEY (Itemno) REFERENCES Item (Itemno)
);
Screen Shot:
How to Name constraints in SQL?
Constraints can be named in the Create Table command. The advantage is that
named constraints can be easily deleted or updated using the Alter Table
command. A constraint can be named by using the keyword CONSTRAINT
followed by the name of the constraint and its specification.
Example:
Create Order
(
Ono int Primary Key,
Odate date,
Itemno int,
Qty int,
Total int,
FOREIGN KEY (Itemno) REFERENCES Item (Itemno)
);
Screenshot:
Drop table
Syntax:
Example:
DROP TABLE Orders;
Alter table
It is used to modify structure of a table. Following are the alteration can be done
using this command:
Adding a column:
Example:
Dropping a column
Example:
Modifying a table:
A column can also be modified using Alter Table command as given below:
Insert command
This command is used to insert a tuple in a relation. We must specify the name of
the relation in which tuple is to be inserted and the values. The values must be in
the same order as specified during the Create Table command.
Syntax:
Example:
Screenshot:
Update command
Update command is used to modify the attribute values of one or more tuples in a
table.
Syntax:
UPDATE <tablename>
SET <expression>
WHERE <criteria>
Example:
UPDATE Item
SET Rate = 30
WHERE itemno = ‘i0001’;
Screenshot:
Delete command
Syntax:
DELETE FROM <tablename>
WHERE <criteria>;
Example:
Screenshot:
Select command
Syntax:
Screenshot:
Code:
Screenshot:
Query3: display name of items which rate is more than 100.
Code:
Screenshot:
Code:
Screenshot:
Query5: retrieve item details which rate is less than 100 and qty is more than
100.
Code:
Select * from item where rate < 100 and qty > 100;
Screenshot:
Post navigation