Database Management Systems
Database Management Systems
Database:
A Database may be defined as a collection of interrelated data stored
together to serve multiple applications.
Purpose of DBMS:
A database system should be a repository of the data needed for an
organizations data processing.
In typical file processing system , permanent records are stored in various
files. A number of different appln programs are written to extract records
from and add records where as using a Database Management ystem will
reduce data redundancy!duplication of data", controls data inconsistency,
facilitates sharing of data, enforces standards and also ensures data
security.
DBMS:
#efers to a software that is responsible for storing, maintaining and utilizing
databases.
Different Data Models:
#elational Data Model
$ierarchical Data Model
%etwor& Data Model
Relational Data Model:
#elation is a table i.e. data arranged in rows and columns.
'uple( #ows of a table
Attributes( columns of a table
Degree( 'he no of attributes in a relation determine the degree of a
relation.
)ardinality( 'he no of tuples in a relation.
Introduction to MYSQ
M*+, was introduced by company M*+, A- in weden by David Axmar&,
Allan ,arsson and Michael Monty . M*+, is the most popular and powerful
relational database management system !#D-M". +,!tructured +uery
,anguage" is a database language that is used to retrieve, insert, delete and
update stored data.
!"aracteristics of MYSQ:
M*+, is a open source software which re.uires no payment for its usage
Its a fast and reliable application.
It understands A%I standard based +,.
It provides portability with different compilers and can wor& on many
different platforms li&e /indows , ,inux0.
It is easy to install and can handle large sets of data.
It offers a privilege and password system that is very flexible and secure.
It provides many data types to support different types of data. It also
supports fixed1length and variable1length records.
MYSQ
1. State categories of SQL statements (ANSI SQL 99 standard commands).
2. Create a database
3. Create a table.
4. Add rows to a table.
5. Retrieve data in varios wa!s from table sing S"L"C# statement.
$. %is&la! data in a sorted wa! sing 'R%"R () clase.
*. +odif! data stored in a table.
,. -iew strctre of a table
.. +odif! strctre of table
1/. %elete rows from a table.
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2.Create a database:
mysql> CREATE DATABASE School;
o&en t1e Sc1ool database2
mysql> USE School; -> Statement entered b! ser
Database Chaned -> %is&la! b! s!stem
!.Create a table.
Synta":
CREATE TAB#E $Table%ame>&$Col'mn%ame(> $Data Ty)e(>*
$Col'mn%ame2> $Data Ty)e2>*+ *$Col'mn%ame%> $Data Ty)e%>,;
E-:
mysql> CREATE TAB#E #earner&Roll%o .%TE/ER*%ame 0ARC1AR&22,,;
S&&ose if want to c1ec3 w1et1er t1e table was created or not
means4
3.Add ro4s to a table.
is sed.
5 Semicolon is standard way to end SQL
statement.
"62
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000
"62
#o dis&la! all t1e databases 4
+!s7l8 s1ow databases9
Database
:nformation;sc1ema
+!s7l
#est
%atabase can be removed or deleted sing %R'< command.
+!s7l8dro& database sc1ool9
D56erence bet4een Char and 0archar dataty)es
C1ar datat!&e s&eci=es a =>ed lengt1 c1aracter string. ?1en a
colmn is given datat!&e as c1ar(n@4 t1en +)SQL ensres t1at all t1e
vales stored in t1at colmn 1ave t1is lengt1. :f a vale is s1orter
t1en blan3s are rig1t A&added.
-arc1ar s&eci=es a variable lengt1 c1aracter string.?1en a
colmn is given datat!&e as varc1ar(n@ t1en t1e ma>imm siBe is n
b!tes. "ac1 vale t1at is stored in t1is colmn stores e>actl! as !o
s&ecif!4 no blan3s are added
"62
ADD:
(e>@
+'%:C)DCEAFG"2
%R'<2
2
"62
Us5n calc'lat5ons:
mysql> SE#ECT %ame*7ar8s(9:.:2;7ar8s( <R=7 St'dent ;
mysql> SE#ECT %ame*7ar8s(-(: <R=7 St'dent ;
mysql> SE#ECT %ame*7ar8s(>2 <R=7 St'dent ;
e":
&=r,
?e can ma8e the q'ery o't)'t more )resentable by 5nsert5n 5tems s'ch as
symbols or te"t 5n the q'ery o't)'t.
E-:
1. To d5s)lay the names and mar8s o@ all st'dents 4ho haAe
sec'red mar8s aboAe B:.
2. ?hat 4o'ld be the mar8s o@ my st'dents 5@ 4e 5ncreased
by 2 @or all those st'dents 4ho sec'red mar8s belo4 B:C
3. To d5s)lay the deta5ls o@ the st'dents 4ho haAe sec'red
atleast D! mar8s.
5, D5s)lay the st'dents 4ho scored mar8s less than E:.
55,D5s)lay the deta5ls o@ the st'dent F/'r)reet Ga'rH.
555,D5s)lay the rollno and mar8s o@ the st'dents 4hose
rollno 5s less than !.
5A,D5s)lay the rollno and mar8s o@ the st'dents 4hose
rollno 5s not eq'al to !.
A, D5s)lay the rollno and mar8s o@ all st'dents other
than F7an5 G'marH.
=R II
A%D JJ
%=T K
4. To d5s)lay roll n'mbers and names o@ st'dents 4ho haAe
sec'red mar8s aboAe L: b't belo4 B:.
(.To d5s)lay roll n'mbers and mar8s o@ st'dents 4ho haAe
sec'red mar8s 5n the rane L: to B:&5ncl'd5n L: and B:,
.nstead o@ 's5n MBET?EE%N o)erator yo' can 'se the
@ollo45n statement also:
E-:
1. To display the details of students who have their names endin with Sen.
SYNTAX:
To display details of the students in descending order of marks:
INSETIN! "#S IN AN"T$E %ET$"&:
'"(
Synta)
No*+
E):
so *e *ant
to
"utput:
or %athematical functions:
,- ."#E'X+Y( " ."#'X+Y(
eturns the /alue of X raised to the po*er of Y
E):
0- ound:
!"#N$%&) '( If num)er of decimal places is not specified or is *ero+ the
Num)er rounds to the nearest inteer "! %, decimal places)
!"#N$%&+$) '( !ounds the arument & to $ decimal places
i) If neative value is specified for precision+ it counts off that value
left from the decimal point.
ii) If positive value is specified for precision+ it counts off that value
riht from the decimal point.
-./
0. Truncate/
-&/
1. 12A!% )
3. L-N4T2/
-&/
0. 1"N1AT/
-&/
1- INST:
EX:
2- 3"#E'( " 34ASE' (
EX:
5- 6..E' ( " 64ASE' (
7- 3E8T' (
9- I!$T' (
:- 3TI%' (
,;-TI%' (
,,- TI%' (
,0-S6<STIN!' (
,=-%I&' (