12th DataBase
12th DataBase
Database Management
System
WHAT IS DATABASE?
The DBMS provides users and programmers a systematic way to
create, retrieve, update and manage database.
Users of Database
Native Users – Who knows nothing about the database but
interacts with the system by invoking one of the application
programs that have been written earlier.
Sophisticated Users – performs the same task of data entry
not by using any application program, but by means of query
language like SQL.
DBMS Provides Abstractions
Abastraction means hiding details.
•Physical Level:- this level specifies how data is stored in
memory.
•Logical Level:- what data has been stored and what is the
relationship among them.
•View Level:- It just provide view of data does not specify
storage of data.
Advantages
Multiple user interfaces:- Many user can access similar database.
Redundancy control:- No double copy is permitted.
Backup and Recovery :- DBMS provides backup after failure.
Authorized Access:- Only authorized users can access database.
Fields / Attributes
Student
Roll Name DOB Age
Tuple /
1 Tanmay Dutt 14-03-1965 50
Record /
2 Naina Batra 02-11-1965 50 Entity
3 Garvit Agarwal 28-12-1965
Degree 50
Entity Set
Values
Few Terminologies
Schema – the logical structure of the database (e.g., set of
customers and accounts and the relationship between them).
Instance – the actual content of the database at a particular point
in time.
Degree – the number of columns associated with a relation or
table.
Cardinality – the number of rows in a table.
Domain – the range of possible values for an attribute.
e.g. – The domain for the attribute gender may be {‘M’, ‘F’}.
The domain for the attribute title may be { ‘Mr.’, “Ms.’, ‘Mrs.’, ‘Dr.’}
SQL
(Structured Query Language)
Structured Query Language
• SQL is Structured Query Language, which is a computer
language for storing, manipulating and retrieving data stored
in a database.
• All the Relational Database Management System like MySQL,
MS Access, Oracle, Sybase, Informix, SQL Server use SQL as
their standard database language.
Why SQL?
SQL is widely popular because it offers the following advantages-
• Allows users to access data in the RDBMS.
• Allow user to define and manipulate data.
• Allows user to create and drop databases and tables.
• Allows user to create view, stored procedures, function in a
database.
• Allows users to set permissions on tables, procedures and
views.
Brief History of SQL
• 1970 – Dr. Edger F. ‘’Ted’’ Codd of IBM is the known as
the father of relational database as he describes a
RDBMS model.
• 1974 – SQL appeared.
• 1978 – IBM worked to develop Codd’s ideas and
released a product named System/R.
• 1986 – IBM developed the first prototype of relational
database and standardized by ANSI. The firts RDBMS
released by Relational Software which later known as
Oracle.
SQl Commands
Though SQl get used to establish relationship between the Front
End and Back End of any software, it has many commands to
work with. These commands are classified into the following
groups based on their nature.
• DDL (Data Definition Language)
• DML (Data Manipulation Language)
• DCL (Data Control Language). Oftenly it also called DQL (Data
Query Language).
DDL Commands
Get used to define the
things like database,
table, view etc.
Commands
DML Commands
Get used to manipulate the
data. To insert, delete and
update the values.
DCL Commands
Get used to cotrol
the manipulation of
data by granting it
or by rollback.
SQL Syntax
SQL is followed by a unique set of rules and guidelines called
Syntax.
• All the SQL statements starts with any of the keywords like
SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, CREATE,
USE, SHOW etc.
• All the statements ends with a semicolon (;).
• The SQL is case insensitive, which means it does not check the
case.
• SELECT and select have same meaning is statement.
Variables & SQL Datatypes
Variables
Refers to memory locations, get allocated by System and/or
program to store the values (entered and/or calculated) during
the execution of program.
Datatypes
Define what type of data a variable can hold or store.
• smallint (can store upto 4 digits)
• mediumint (can store upto 5 digits)
• int (can store upto 11 digits)
• double (can store upto 16,4 [here 16 is total width and 4 is for
decimal place])
SQL Datatypes
• float (can store upto 10,2 [here 10 is total width and 2 is for
decimal place])
• decimal (can store upto m,n [here m is total width and n is
for decimal place])
• char (can store single character)
• varchar(n) (can store upto specified width [max 65536])
• date (can store date only)
• datetime (can store date and time)
• time (can store time only)
SQL Commands
To Display all Databases
SHOW DATABASES
To Create Database
CREATE DATABASE <databasename>
To Open Database
USE <databasename>
SQL Commands
To Create Table
CREATE TABLE <tablename (fieldname
datatype constraint, fieldname datatype
constraint,.........)>
USE <databasename>
Get used to open the database to work with.
• Ex – USE student;
Commands
CREATE TABLE <tablename (fieldname
datatype constraint, fieldname datatype
constraint, …….)>
• Get used to create table with given
fieldname and datatype.
• Ex – CREATE TABLE records (sno int, name
varchar(20), clas int, sec char(1), gnd
varchar(6));
Commands
.
Commands
To apply the condition with Group By, we use
HAVING. Conditions can be given only for the field
that is used for grouping.
SELECT function <fieldname> FROM <tablename>
GROUP BY <fieldname> HAVING <expression>
Ex- SELECT clas, avg(math) FROM pupil GROUP BY
clas HAVING clas>=10;
Commands
As you can see in this table record no. 3 and 6 have
no information regarding class and section. To
make changes in existing records UPDATE
command get used.
Commands
UPDATE : get used to update the existing record.
UPDATE <tablename> SET <field> = <value>
Ex- UPDATE record SET clas=10;
It will set clas=10 for all the records. It get used
when we want to make changes in all records.
UPDATE <tablename> SET <fieldname> = <value>
WHERE <expression>
Using this we can make changes only in those
records which meets the condition given using
WHERE clause.
Commands
Ex- UPDATE record SET clas=10 WHERE sno=3;
Before After
Commands
This is the structure of table record.
To Alter table
Syntax
ALTER TABLE <tablename> ALTER <field> SET
DEFAULT ‘value’;
DEFAULT
After
ALTER
command
DEFAULT
Auto_Increment
Auto-increment allows a unique number to be
generated automatically when a new record is
inserted into a table.
Often this is the primary key field that we would like
to be created automatically every time a new record
is inserted.
To Create table
Syntax
CREATE TABLE <tablename> (field datatype
PRIMARY KEY AUTO_INCREMENT, field datatype,
….)
Auto_Increment
Now one can enter the records. User can omit the
entry for sno. If it is first record, it will store 1 as
value.
Auto_Increment
User can
also provide
the value
for these
fields. It
always
increase
by one
according
to last entry.
Auto_Increment
User can assign
later using alter
Command-
ALTER TABLE
<tablename> MODIFY <fieldname> <datatype>
AUTO_INCREMENT;
NOT NULL
To Alter table
Syntax
ALTER TABLE <tablename> ADD <fieldname datatype
CHECK expression>;
RDBMS
RDBMS have more than one table related to each
other. There is a connection between them using
any key (field). In the first table it is called Primary
Key and in the second table if it treated as
Foreign Key.
Foreign Key
D:\2021-2022\Content\12th Common\To
Try.pdf
Thank You