Inbound 1266701907454259617
Inbound 1266701907454259617
~
~~
a, P~~::ishers Pvt . Ltd.
ass
(A relation al databa se is a collecti on of multlpl e tables that could be related
to each othe
consist s of records , which gives informa tion about the items in the table.
A record consistsr. ~ ta~
which contain informa tion about the record ) RDBMS lets you create, 0
update and adrnin• ri,~
1ster
relation al databa se.
a~
Components of RDBMS
A relation al databa se has the followin g major compo nents.
Table
(Tables are the places where all the informa tion in your databa se is storec:V
They have to be creat d
are used to keep t~e ~~t
no other part of the databa se can functio n until the tables are created Qables
tabulat ed in rows and column 's)
Here we have a table, i.e. STU D ENT with 7 column s and 5 rows (includ ing
headin g).
STUDE NT
Roll No Students Name Class English Hindi M aths Total
1 Rahul Singh X-A 70 65 95
2 Priya Gupta X-A 82 75 85
3 AlokJai n X-A 66 90 80
4 Payal Shina X-A 75 80 75
Record
(A record is a row in a table that ~ntain s informa tion about a given person
, produc t, or a n event. It
also known as row , entity or t uple.)
In the table given below, you can see the highligh ted row incorpo rates
the data of all the field s and !
called record. Similar ly, all the other rows also contain the data of column
s of table.
STUDE NT
Roll No Students Name Class English Hindi Maths Total
1 Rahul Singh X-A 70 65 95
Showing Tables
After creating the table, let us look at the list of tables you have created in your database.
Syntax:
SHOW TABLES;
1. In mysql> prompt, type SHOW TABLES;.
Describing Tables
You can view more detailed information about each table by using DESCRIBE or DESC command.
Syntax:
DESCRIBE table_name; or OESC table_name;
1. In mysql> prompt, type DESCRIBE Members;.
Altering Table . . .
The ALTER . dd d te or modify columns in an existing table.
I
TABLE statement Is used to a , e e ,
ADo COLUMN
To add a column in a table use the following
· syn tax.·
Svntax: '
ALTER TABLE table name
A -
DO column_name datatype; IT PLANET - 8 (CodeAI Plus) A~
Dropp ing Database
The DROP DATABASE statement is used to delete an existing database .
Syntax:
DROP DATABASE database_name;
Note: Be careful before dropping a database. Deleting a database will result in loss of co
information stored In the table in a database rr,p/,..
.,.
1. In mysql> prompt, type DROP DATABASE Sports_Club;.
2. Press the Enter key. It will delete the database from the list.
CREATING TABLE
Before creating table in MySQL you must create database and use it.
ISports_Club !- - - -- - - - Database
I
Members +-- - - - - - - - -Table
FleklName Field Type Description
Member_lD Integer !INTEGER)
Member_Name Text [VARCHAR)
Activities Text [VARCHAR]
Charges Integer (INTEGER)
Creating a Table
The CREATE TABLE statemen t is used to create a new table in a database.
Syntax:
CREATE TABLE table_name (
columnl datatype,
•
column2 datatype, I
1
rt@s1+ i;;\,t·[email protected]~
column3 datatype, While naming field/column in MySQL, don't use
period (•) forward slash ( / ), comma (,) etc.
);
The table_name specifies the name of the table.
The column parameters specify the field names In the table.
The datatype parameters specify the type of data the column can hold (e.g. varchar, integer,
date, ~id-
. ' . '
1. In mysql> prompt, type
CREATE TABLE Members
(
Member_lD INT,
Member_Name VARCHAR(lOO),
Activities VARCHAR(lOO),
Charges INT,
PRIMARY KEY (Member_lD)
);
,s
~ PM P,bUshers Pvt. ltd .
2. Press the Enter key.
• Query OK message appears.
Syntax:
UPDATE table_name SET fleld_change=value WHERE field_ criteria=value;
You need to specify which table needs updates, and which column(s) in the table needs Updat
e. lo
update the charges whose Member_lD is 2, follow these steps.
1 1. In mysql> prompt, type
UPDATE Members SET Charges=sooo
WHERE Member_lD=2;
2. Press the Enter key.
• Query OK, message appears.
NOTE: Take care not to d elete too much o r t he wro ng d ata w hile using DELETE co m m and .
~ 70
PM Publishers Pvt. Ltd.
r,tYSOL QUERIES querying a database is one of
st for a specific data fro~ -~ -: fatabase. The cap abi lity of
auerv is a reque ery is sim ply a question rep
resented in a way
ture s. In oth er wo rds , a Qu
the- most pow erf ul databa se fea to find the answer to a question, you
wall l'lave to
ers tan d. If you wa nt
that database progr~m can und ry has been created, you can
run it to get the desired
que ry firs t. On ce you r que
cr"eate a corresponding
informat ion.
em en t
Using Se lec t Co mm an d/ St at most applications,
of fiel ds you wa nt to ext ract from a certain table. In
set
The SELECT command lists a ge (DM L) command.
ECT is the mo st com mo nly used Da ta Ma nip ula tio n Langua
SEL
nd or sta tement.
h UPDATE and DELETE comma
WHERE clause is also used wit
em en t
Us ing Up da te Co mm an d/ St at a. The UPDATE statemen
le, you nee d to cha nge or upd ate you r data wit h new dat
Sometime In you r tab
is used for this purpose. 69
IT PLANET - 8 (CodeAI Plus)
1. In mysql> prompt, type
ALTER TABLE Members
ADD Timing TIME;
2. Press the Enter key.
• Query OK message appears.
DROP COLU MN
To delete a column in a table, use the following syntax:
Syntax:
ALTER TABLE table_name
DROP CO LUMN column_n ame;
1. In mysql> prompt, type
ALTER TABLE Members
DROP COLUMN Timing;
2. Press the Enter key.
• Query OK message appears.
When you again describe the table, its altered structure appears. It will remove the column
(Timing).
Inserti ng Records in the Tables
After creating the table by building the structure, next step is to insert the records
to it. INS\9
D
statemen t is used to add one record at a time.
Syntax :
INSERT INTO Table_name
VALUES ('val_colu mnl', 'val_colum n2', .... ............. , 'val_colu mnN');
By using INSERT statement, you can add more records to the table.
Droppi ng Table
The DROP TABLE statemen t is used to delete an existing table.
Syntax:
DROP TABLE table_name;
Note: Be careful before dropping a table. Deleting a table will result in loss of complctt!
in'
stored In the table/
syntax:
CREATE DATABASE database_name;
The database_name specifies the name of the database.
• ! ' •
· . 1. In mysql> prompt, type CREATE DATABASE
Sports_Club;.
2. Press the Enter key.
■ MySQl.8.0 Command Line Oient • If the command for creating database is OK then
Query OK, appears.
Showing Database
After creating the database, you can see it in the database list. The SHOW DATABASES statement
is used to show the name of new database.
Syntax:
SHOW DATABASES;
1. In mysql> prompt, type SHOW DATABASES;.
2. Press the Enter key.
• This command will show alphabetical list of
the databases that you have access to.
• Your newly created database (sports_club)
also appears in the list.
Using Database
Now that your database is created, you have to select it for use.
Syntax:
USE database_name;
• ~I.O'--ci Line Olene 1. In mysql> prompt, type USE Sports_Club;.
2. Press the Enter key.
• Database changed message will appear.
Data Types
In ~ table: each field has a data type that defines what you can store in it. Data entry
is restricted
vahd entries for the type you choose. For example, you cannot enter letters in a field set
f
to Numbj.
The following are the available data types:
• INTEGER : It is a whole number (no decimal) .
• CHAR (SIZE): It holds fixed length string. It can have a maximu m size of 255 characters.
• VARCHAR (SIZE): It holds variable length string. It can have maximu m size of 65535 characte
rs.
• DATE: It can have values in YYYY/ MM/00 format.
• TIME: It can have hour, minute and second value in HH:MM :SS format.
• TIMESTAMP: It can have year, month, day, hour, minute and second values.
,-·-·-·
i
-·-·-·-·-·-·-·-·-·-·-·-~~
ry,g ,t,
·
Field Name Data Type
i
Predict t h e appropria te data type for the following fields In the Exam table:
I
Exam Time
Fleld Name Data Type iI
Exam Date
Exam_SubJect - I
Student_Age
Student_ Name I
-
, Student_ Photo
- l
·- ·-·- ·- ·- ·- ·-·- ·-·-·- ·-·- ·- ·- ·-·- ·- ·-
·- ·- ·- ·- ·- ·- ·-·-·-· -·- ·- ·-·-·-· - ·-·'
'-0
~ PM Publisher s Pvt. Ltd.
l d t b
r,ffS~~e ofStr the mo st po pu lar rel atio na ma na ge me nt so ftw are tha t is
\'\ .
ge It :sad as~ ~0
SQ
rvwsaL ~ SOL - uct ure d Qu ery Lan gua Oracle M
le ~ eve op ed and supported by Y •
based o . MySQL sto res da ta in tab s ma e up of rows and columns.
corp oration.
g M yS Q L
oo wn loa din g an d In st al lin n sof twa re. Here, you wil l
nit y server ed itio
cia l we bsi te of MySQ L ao d do wn loa d the com mu
Go to the offi Windows.
t o cho ose the Op era tin g System, such as
see the opt ion atio n process.
th ip it an yw he re and double-click file to sta rt ins tall
After downloading e se tup file , unz
ing MySQL.
ctio ns wh ile ins tall
care fully foll ow all the ins tru
MYSQL COMMANDS use d to com mu nic ate wit h the da tab ase. Th
ese com ma nd s are
wh ich are
Commands are ins tru ctio ns da ta to tables, dro p the tab le, mo
dif y the tab le,
ks like cre ate a tab le, ad d
used to perform var iou s tas rm' var iou s fun cti on s:
, etc . My SQ L use s the fol low ing com ma nd s to pe rfo
set Perrnfsslon for us ers ng a tab le, etc.
use d for cre atin g a tab le, de leti ng a tab le, alt eri
(OOL): It is
Data Definition Language
t com e un de r DDL:
Here are some co mm an ds tha
ne w tab le in the dat aba se
• CREATE : Used to cre ate 3 abase
ed to alt er or cha nge the str uc tur e of the existing dat
• ~TER : Us
red in the tab le
the str uct ure an d record sto
PlusA ~
op : Used to de let e bo th
• DR
Eumple of Database
ories and subje cts in II .
A school library stores books of diffe rent categ
each shelf. Therefore,
different shelves with a name assigned on
cular book, they can
Whenever anyone requ ires to search for a parti
easily locate.
In a similar manner, all the data is well-organ
ized in a tabu lar form in
pulated and upda ted
DBMS so that it could be stored, accessed, mani School Library
easily When required.
S)
Relational Database Man age men t System (RDBM
s
gement System. It is simil ar to DBMS that store
~DBMS is an acronym for Relational Database Mana
information in the form of relat ed tables.
-------------•·ij»tN.W!JIIID
..,__,__.... ·•---------------
A. Tick (✓ J ther correrct answerr.
......... ....... are used to keep the data tabulated in rows and c ~
1.
a. Record CJ b. Table ~ c. Field
0
2. .. .............. is used for creating, deleting, altering a table.
a. DDL ~ CL O c. DQL
0
3. .. .............. is used to grant and take back authority from any ~ s e r .
a. DCL O b. TCL ~ c. DML 0
4 Th t I ed to add, delete, or modify columns Is an existing table.
• e ............... statemen s us
a. SHOW TABLE O b. CREATE TABLE O c. ALTER TABLE
S. By usi..g statement you can add one records at a time.
a. INS~R;............... ~ SELECT O c. UPDATE
E.
Information
I
••····· •• •••••h• • •••••••• •••••••• •••••••·
•• • ••••·•• • •··• • •••••••• •· • • ·• ••••• •
• · • ••o•••• •••••• ••••oo OO OO OOo,oo• • •···••
•••• OOOO•oo ••••• •··• •• ••• • I• •• •
........ ............................................ • 0
,s~:;·}:/;J:j!J~:!·~~d
f!qf lfv... ~f · f '"ei~ m
0
m .,110+
ii/•lififHjffi\) b, u~ ue
Divide the studen ts Into groups and d iscuss t he Impor tance of
query In the database. W
~ ¼e- .-e CG!Vl be Mk, c:.-lo cle,
~.0' 1 f' -
~ e
r+1,,,, ¼ e
,h
""1
Online Link
To learn more about Image s, links and tables in HTM L, visit
the website:
Lab Activity
1#1$1ili•iiuhhf.i,t-- j
This activi ty enhan ces data organ izatio n
and mana geme nt skills of the stude nts.
Creat11 a datab asCl with thCl follow i ng tablcr In SOL. -- -
l
N1111e Aae Gender
J 1. show all inform ation about female
students.
Rishabh 15 M 2. update the record of Aarav to chang e his
age t o 17 and view the update d record in
2 Aarav M
16 table.
3 3. Insert a new record w ith the follow ing data :
Himan l 14 F
(6 , "Jaya", 18, "F")
4
Blnit 15 M 4. add a colum n to display date of birth of all
the students.
5
Abhaya 17 F 5. show the records of each studen t with age
>15