0% found this document useful (0 votes)
6 views20 pages

Adobe Scan 21 May 2024

The document provides an overview of Relational Database Management Systems (RDBMS), detailing the structure of databases using tables, rows, and columns. It includes examples of SQL commands for creating databases and tables, inserting data, and querying data using SELECT statements. Additionally, it discusses the use of constraints and the importance of unique values within the database schema.

Uploaded by

kaurekam1227
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views20 pages

Adobe Scan 21 May 2024

The document provides an overview of Relational Database Management Systems (RDBMS), detailing the structure of databases using tables, rows, and columns. It includes examples of SQL commands for creating databases and tables, inserting data, and querying data using SELECT statements. Additionally, it discusses the use of constraints and the importance of unique values within the database schema.

Uploaded by

kaurekam1227
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

arrangedDatabase

data with
Relational
Database
1.4.3
in The
the view a
in
Management
Relational
Database
Management
tabular
tables
that
with
format. data
rows
Systemneeds
and is It
the is to
columns). be
software a
evaluated
database

Itthat System
was system in
operatesefficient
proposed
(RDBMS)
software
on and
by a was
relational
Dr. that
ettective

E.manages
F. introduced
Codd. manner.
schema
and in
RDBMS
Relahons the
maintains
(database
197N.
uses
Dalabase
131
conceptof relations
to represent each and every file.
labes
fhe and Relations Two-dimensional
dit iseasytoimplement and simplify the data in RDBMS. Itare
is the
Once the tables have been set most popular
up, a
data
model.
tables can be created to link them together.
relationship between common colunmns
among

Student Table (Relation)


Primary Roll Number
Key Name CGPA
001 Vaibhav 9.1

002 Neha 9.5


Tuples
003 Harsh (Rows)
8.5

004 Shreya 9.3

Columns
(Attributes)
Fig. 1.1 Relational Model in DBMS
pen is
reated. Example: The
Once
or <databasename>!
mysq> DATABASE
CREATE
&gntax: imporfotr ant
We its first
use wil 7eREATING
Wethe step
CREATE write
1.successful DATABASE
the canabove thing
is
secreate the is
execution. tthat
entionedcommands hat in tocreate
DATABASE
the MySQL,we
that a
tabase database,
we
statement on
have School:
mysql have
with to
ted. gets prompt: to do
any putwhich,
executed,
name. semicolon
we
Before need
a
database at
creating the to
end know
with ofthe
a
table, the all
command.
SQL
name
we statement
needSchool
to One
M,SQL &.0 Command Line Client
Enter password: ***
Welcome to the MySQL monitor. Commands end with ; or \g.
Your My 5QL connection id is 29
Server version: 8.0.19 MysQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. 0ther names may be trademarks of their respective
OwnerS.

Type 'help;' or "\h' for help. Type '\c' to clear the current input statement.
mysql> CREATE DATABASE employeedb;
Ouery OK, 1 rOw affected (0.26 sec)
1.16 CREATICG ATABLE
After creating a database, the next step is to create tables in the database. For this CREAIE
TABLE statement is used.
Syntax:
CREATE TABLE<TableName> (<ColumnNamel><Datalypel>,
<ColumnName2><DataType2>,...,<ColumnNameN> <DatalypeN>);
Example:
Create asimple table named STUDENT with only three columns RollNo, Name and
date of birth in the School database.
To do this, enter the following statement:
mysql> CREATE TABLE Learner( RollNoINTEGER,Name VARCHAR(25), DateOBirth
Date);
Syntax:
names, The
name>; 1.1K
DESCRIBE
their
VIEWING
data
statement
types,
THE
along
can
STRUCTURE
with be
used
the
details to
see
OF
the
of THE
structure
each
TABLE
column.
of
a
table.

It
displays

the
Column
Example:
DESCRIBE
Student:
mysql>
DESC<tablename>;
OR
B student
nysqi
desc
rollnO Field
birth Name

in

1IVpE

VES
YES YES NU1

Key

NULL NULLNULLDefault

Extra |

147
first
1.12.2
4 see We
my NULL:
NQT
QueryOK,mysql>LADplying
rows amountrcptno
rollno Field
fees
date of sql> MySQL
NULL can
how Adding
8.0
in Command
desc create value. toadd
set rcpt apply
0 Line constraint
Client
Constraints
fee; rows
0.00
no
table To
constraint
int date int Type affected, int, do
(9,2)
floatYES
sec) so. while
fee(rollno
amount
weWe while
at
1 the
will can creating
Creating
1
1 NONO
NORNOTL warning
1float(9,2) use set time
NulNL
d int
the 'not
table a
of
following creating Tables:
date null
Ke 0.05 as
primary
sec) on of well
NBLL NEE Detault a the
feescommand field as
key(rollno,rcpt table:
where afterdate

not in creating
Extra the we
null. fees' do the
| not
no)): table: want table.
Le
o
5 mysql>
desc
fee; Query mysql> thfather
e Applying
amount
rcpt_no rollno Field MySQL
ableconcpositeno),so od
hone no fees
date of -> fees 8.0
which os give
OK, Command does £uo
in create incuding
primary rcpt table: it
Line
is an
rows should tru
Client
notUNIQUE: error. an
no
table to
key(rollno, int have example enter
NOLL.
affected,
(10)
t(9,2) intdate int Type here,
fee(rollno have
a
amount a
mobile We
unique Let one
ofNOLL
1warning
(0.03
sec)rcpt uscan
float
int
phone. primary in
assume set
values the
YES NONONO no));(9,2)
YESUNI Nåll
Unique
date lo key key date
PRI
and that
PRI mobilephone_no do
Key ashas of
of
t s0, can weon
NULL NULL NULL NULL NULL fees well.been fees
Default wealso have a
date
field column,
contain
wil
mobilephone set
use which on
varchar not
xtra
the MySQL
two
null, null
following should
(10) fields
in
unique case no wil
have (rollno
reject
field
command any
student's in all and the
the
unique entry 151
reot
fee
in
present
1.12.3
we
Example:
TABLES:
mysql> SHOW
Syntax:
SHOW TABLES; might a
make Once
in Viewing
the the
current table
spelling the
mysqd>
tables
show is
sstudent fee MySQL Tables
database,created,
Tables
schoo in 8.0
Command
mistake
in in
Linc
we wethe
set
while
can workon
it
Database
0 use
typing
SHOW
ec) theevery

TABIES name day

offor
the
cOmmand.entering
table.

records.
To
see
Sometimes
list a S
of
t
Ekample:
Uas No 3,...,.J. optional. names
are column Here,
value value2, [(value
1, 3,...), value
ue (<COLUMNNAMES>)
val2, (yalue
1, VALUES <TABLENAME> INTO INSERT.
Syptax:
syntax.following the has
mand command.
This INTO INSERT the use table,
we records
ain new enter Now,
to
emptu means value NOLL quotes. table. the value
in
any without NOLL written
as should
be value NULL
YYMM-DD' format the single/double
quotes
in entered
in should
be Date
single/double
quotes. enclosed
in been must values text String or
quotes. without numerals entered
as bemay values Numeric
thpoiat nts major
syntak relation: records
ain inserting while mind in
kept should
be
the records,
us let inserting command
for theexampleof and
table. the thetaking understand
Before termed
as are table the inside entereddata/values The
inside data entrecords.
er toneed we
inside
it, table database
anda the create we
Once
COMMAND INSERT 1.
Client
Command Line
IMySQL8.0
501 2022 -01 -02
1101 5500. 00
501 2022-04-03 1105 6767687334
502 2022 -01-03 5000. 008735436310
2022-01-03
1102 520O.00 7867688334
503
503 2022-04-03 11035300.00
1106 5100.00
7834588210
7282997782
504 2022-01-03 1104 5500. 00 9834520920
6 rowS in Set (.03 sec)

oNsal> insert into tee


Query OK, 1 row Values(505,"2022-06-07",1107,5000,6746456789);
affected (.02sec)
mysql> select from fee;
rollno date offees rcpt no amount mobilephone no
501 2022-01- 02 1101 5500.00 6767687334
501 2022- O4 03 1105 S000.00 8735436310
502 2022-01-03 1102 5200. 007867688334
503 2022- O1 03 1103 5300. 007834588210
503 2022- 04- 03 1106 5100.00 7282997782
504 2022-O1 03 1104 5500. G0 9834520920
505 2022-O6 07 1107 5000.00 6746456739

7 rows in set (0.00 sec)


2.SELECT COMMAND:
CEI ECT Command is used to view the data from a
table/relation in a database, To
Liouethe records from one or more tables depending upon a condition or a query we use
SELECT command.
Syntax:
SELECT<column name list >/ * FROM <tablename> [WHERE < condition> ORDER
BY <Fieldname>];
Here means all the columns. We can mention individual column names separated
by
WHERE and ORDER BY clause later.
comma at the place of column name list. We will discuss
the table student:
Example 1: To display all the columns from
mysql> Select * from student;
5 |enrolimentmysql>
no

in select
202207 202201
202202
202205
202206
t

(0 *
01 from
rollno
name
c Somya
107 106 105amit
102 101 student;

tarun umang Sumit

2001-12-11
01-05-02
2002-02-10 dob
-12-11 2001-10-10

45, 105,address
134/23, 10/20,
1/123,
tonk civil
malviya
awaharshyam
road,
lines,
nagar, nagar,
nagar, surat
jaipur
kota
kota jodhpur

jaipur jaipur
|Mjaipur
jaipur|M
aipurF |M Mcity

gender |
clal
Let For
values. repeat
val
the uees,
tdhen
mysql> example: selectkeyword
us isTINCT Distinct is
keyword
select see
how
command
city
DISTINCT
from isthe
given used
5 SELECT
mysql
student: to
ws alwarkota kota city
jaipurJaipu withdisplay
keyword
in select DISTINCT
statement
set unique
unique
helps.
0 city
values
values
keyword,gives
from
c) thethe
(without
student; result
thenresult

repetition).
it set
is
with
used
repeated
to
eliminate af
column
values
repeatedcontains
only.
If
wal
mysexample.
ql> For
Select
+
3 DISTINCT
kota | city||mysql>
jaipur
rowS alwar

in select city
set student;
îom
(0.00 distinct

sec)
city

from

student;
queryas:the
WHERE<condition>;
amel>|,<columnname
<tablename>
mysqlselect>,....]FROM whircehtrieveretrieve
Example atax: criterion/ data can on(i ) Data
4
mysql>
enrollment fetch
E
based
in select*from
SELECT'wisl trecords
atebasedmentotWHERto
02207 202201
202202
202205 1: clause
Display
* mentioned.
those
only
no on
from
roNno a usedwe
is in
107 105 102 101
student the
student SELECT
amit
Sumit
records
2-02-10
-11umangnamedob where
details a
given
records
where condition.retrieve
gender="M";
2001-10-10
2001-12-11
of that Statemnent
condition.
those
gender="M":) meet
| address
45,
1/123, 10/20, 105, students condition
Criterion/
tonk civil
criteria
the
jawaharmalviya This from
road,
lines,

nagar,
nagar,surat where means the
jaipur
table
jodhpur
kota
gender that
made is but
Icity
gender | WHERE
alwarjaipur kota
jaipur
is with
male.
M M M
using WHERE
clause
+
We an
will is
expression clause
used
write
Hndling pattern matching using LIKE Operator
Mn matchingmeans the values similar to a
pattern. For Pattern matching, we work
Abrough wild cards_-There are two wild card characters:
1. %(percent)- used to represent zero, one, or multiple characters.
2. (underscore)- used to represent a single character.
2 mysql> Example
ows enrollment 2 Example
mysql> rows
mysql>
enrollment mysql>select
in202208 select
202207
set in select
select 2: 202201|
set 202206 1:
00
ec) no * Display
from (0.01 no
*
Display
rollno * | from
109 107
*
student from sec)
rollnoname trom
those sumit101somya106 student those
tarun
anil name student
where student
student
where names
1-07-09
2002-12-11 dob citý where 2001-05-02 dob name where
details 2001-10-10
civil
105, of
like
like the
city name
where students
3,jawahar
12/45 address like | "S%";
134/23,address like
civil city 'S%: that
name shyam
lines, start
jaipur
1ines,
nagar,
kota nagar,
surat has with
only kota letter
|Mgender |
Suratmalwarcityl
5 |city
gender I
letters. kota|Mkota|E «.
s UPDATE
Command
commandisused to modify the
the data values of
UPDATE
isaDMLcommand which is usedto make changes records within the table. Update
in the values entered in the table.
Suntax:
UPDATE<tablenames
SET <columnname> <value>, (<column name>
WHERE
E<condition>]; <value>,...]
command can be used to update one or more
The columns with the same UPDATE
command. We can mention any specific record records that matches a criterion by
the WHERE clause. using
Example1: Update the name of the employee as "Tejas Singh" where the employee id
is402,
musal> update employee set emp name="Tejas Singh" where empid=402:
402 Tarun Goyal 2001-05-06 48750.00 5112
403 Anil saxena 2001-12-12 67000.00 5111
404 Ashok Sharma 2001-10-16 66000.00 5110
405 Neeraj Saxena 2002-10-12 51000.00 5111
406 Rajesh Sharma 200111-22 61000.00 5110
407 NULL oD001-02 58000.00 5112
408 Jay Ashwini 2001-05-22 66000.00 5111
409 Somesh bhatnagat 2001-03-04 61000.00 5110

9 rows in set 0.00 sec)

mysql> update employee set emp name Tejas S1ngh" where empid=402;
Query 0K, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings0

mysql> select* from employee;


empid emp name |dob salary deptid |

401 shyam mathur 2001-03-21 55000,00 5112


Tejas Singh 2001-05-06 48750. 00 5112 |
402 Anil saxena 2001-12-12 67000.00 5111
403 2001-10-16 66000.00 5110
404 Ashok Sharma
Neeraj Saxena 2002-10-12 51000.00 5111
405 Rajesh Sharma 2001-11-22 61000.00 5110
406 2002-01-02 58000.00 5112
407 NULL 2001-05-22
Jay Ashwini 66000.00 5111
408

You might also like