0% found this document useful (0 votes)
37 views135 pages

12th DataBase

Uploaded by

a.solankii2007
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)
37 views135 pages

12th DataBase

Uploaded by

a.solankii2007
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/ 135

DBMS

Database Management
System
WHAT IS DATABASE?
The DBMS provides users and programmers a systematic way to
create, retrieve, update and manage database.

Data:-The collection of related facts and figure is called Data.


DataBase:- Collection of related data is called database.
DataBase Management System:- Software used to maintain
database is called database management system.
DBMS Softwares:- MS Access, Oracle, SQL Server, MySQL DB2,
DATABASE
MS Excel – Does possess data management capabilities, but not
a pure DBMS. Languages used by DBMS Softwares are SQL,
PL/SQL

Applications – Banking, Airline,


Retail, Manufacturing, Telecommunication, Universities, etc.

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,.........)>

To Display all Table name for current


Database
SHOW TABLES
Database Name : student
Table Name : records
Commands
SHOW DATABASES
• Get used to display all the databases
available in RDBMS
• Ex – SHOW DATABASES;
Commands
CREATE DATABASE <databasename>
• Get used to create database.
• Ex – CREATE DATABASE student;

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

After this, table will be shown using SHOW


TABLES command.

It means now table is ready to work with.


Commands
INSERT INTO <tablename> VALUES (value,
value, ……)
• Get used to insert the record in the table.
• Ex – INSERT INTO record VALUES (1,’Garvit
Agarwal’,10,’A’,’Male’);

In this way we can enter the other records.


Commands

Rules to enter the things-


• All the string values should be enclosed in
single quotes. As you can see in the above
query, Name of Student, Section and
Gender is within single quotes.
• Follow the sequence for values as the fields
is defined in table structure.
Commands

• Follow the sequence for values as the fields


is defined in table structure.
and in this we are skipping the entry for class
and section. As per rule we have to maintain
the values sequence while entering the data.

There is an another way, mention the field


names for you are making entries.
Commands
INSERT INTO <tablename> <fieldname,
fieldname,….) VALUES (<value, value, …>)
• In this way we can mention the field name to
make entries. Field name should get used
before keyword VALUES.
• Ex- INSERT INTO record (sno,name,gnd)
VALUES (2, ‘Ipsita Sen’,’Female’);
Commands
As you can see there is no values stored in
fields clas and sec for second record.
Commands
INSERT INTO <tablename> VALUES (value,
value, ….),(value, value, ….)
• User can also enter more than one records at
same time.
Ex- INSERT INTO record VALUES (3, ’Pooja
Batra’, 9 , ’A’ , ’Female’) , (4 , ’Devashish
Gupta’, 9, ’A’, ’Male’);
• This will enter 2 records at the same time in
table.
Commands

• You can see the records entered into the


table
Commands
To try SELECT command we need a table which
have diffrent type of fields, so that we can
understand it better way. To describe this
command we are using table called pupil
Commands
SELECT * FROM <tablename>
• This will display all the records of specified
table. Here * (astriesk) stands for all columns
(fields).
Commands
SELECT <fieldname, fieldname, …..> FROM
<tablename>
• This will display the values of specified fields
only. Ex - SELECT sno , name, gnd from
pupil;
Commands
SELECT * FROM <tablename> WHERE <fieldname = expression>
WHERE is a clause which provide facility to provide different types
of conditions to fetch matching records for. User can use relational
operator like <, >, =, !=, <> to establish relation between two
operands (can be fields or values)
• Ex- SELECT * FROM pupil WHERE clas=9;
• Ex- SELECT * FROM pupil WHERE clas!=9;
or
• SELECT * FROM pupil WHERE clas<>9;
• Ex- SELECT * FROM pupil WHERE sci>50;
• Ex- SELECT name, hindi, eng, sci, math FROM pupil WHERE
sci>50;
• Ex- SELECT * FROM pupil WHERE gnd=‘Male’;
Commands
Ex- SELECT * FROM pupil WHERE clas=9;
• It will display the records in which class is 9
Commands
Ex- SELECT * FROM pupil WHERE clas!=9;
or
SELECT * FROM pupil WHERE clas<>9;
It will display the records in which class is not 9
Commands
Ex- SELECT * FROM pupil WHERE sci>50;
• It will display the records in which students
secure marks in science more than 50.
Commands
Ex- SELECT name, hindi, eng, sci, math FROM
pupil WHERE sci>50;
• It will display the value for field name, hindi,
english, science, maths in which students
secure marks in science more than 50.
Commands
Ex- SELECT * FROM pupil WHERE gnd=‘Male’;
• It will display all the record of male
candidates.
Commands
Ex- SELECT * FROM pupil WHERE gnd=‘Male’;
• It will display all the record of male
candidates.
Commands
AND / OR
To provide the conditions for two or more fields
at same time AND/OR get used.
• AND – Situation in which, we want all the
condition must be true, AND get used .
• OR – Situation in which, any one condition can
be true to fulfill the requirement, we put OR
over there.
SELECT * FROM <tablename> WHERE
<expression> AND/OR <expression>
Commands
Ex- SELECT * FROM pupil WHERE clas=9 AND
sec=‘A’;

Ex- SELECT * FROM


pupil WHERE clas
<>9 AND sec=‘A’;
Commands
Ex- SELECT * FROM pupil WHERE clas=9 OR
sec=‘A’;
Commands
Ex- SELECT * FROM pupil WHERE clas>=8 AND
clas<=10;
or
Ex – SELECT * FROM pupil WHERE clas
BETWEEN 8 AND 10;
Commands
BETWEEN – Provide the range of any field to
display matching record for given criteria. User
can provide start range and end range.
SELECT * FROM <tablename> WHERE
<fieldname> BETWEEN <start> AND <end>
Commands
NOT BETWEEN – Provide the range of any field
to display not matching record for given criteria.
User can provide start range and end range.
SELECT * FROM <tablename> WHERE
<fieldname> NOT BETWEEN <start> AND <end>
Commands
To provide multiple values for same field oftenly
we use the following format-
SELECT * FROM pupil WHERE clas=5 or clas=7 or
clas=9 or clas=12;
What if we want to provide many values for
same field, there is an another method called IN.

IN– Provide the multiple values for single field to


check all.
SELECT * FROM <tablename> WHERE
<fieldname> IN (value, value , value, ….)
Commands
SELECT * FROM pupil WHERE clas=5 or clas=7 or
clas=9 or clas=12;
or
SELECT * FROM pupil WHERE clas IN (5,7,9,12);
Commands
NOT IN– Provide the multiple values for single
field to check all, not to display matching
records for..
SELECT * FROM <tablename> WHERE
<fieldname> NOT IN (value, value , value, ….)
Commands
I am trying to display all those names, which
starts with aplhabet ‘G’

SELECT * FROM pupil WHERE name=‘G’;

There is no record to display because it is not


searching starts with, it is searching the entire
name as ‘’G’’.
Commands
LIKE – It matches the pattern for string values.
It uses 2 symbols % and _ .
% denotes any character and any number of
characters.
_ denote single character at specified place.

EX – SELECT * FROM pupil WHERE name LIKE


‘G%’;
It says name starts with G and rest have any
and any no. of characters.
Commands
.
Commands
NOT LIKE – It display all those records which
not matched with given pattern.
EX – SELECT * FROM pupil WHERE name NOT
LIKE ‘G%’;
Commands

Searching for first character ‘G’ and last ‘a’

Searching for second character ‘a’ in value.


Commands

Searching for second and second last


character as ‘a’ in value.

Searching for third character as ‘a’ in value.


Commands

Searching for exact 8 characters in first query


and 9 characters in second query.
Commands
User can also perform calculations in the
query but that is only for display purpose, it
doesn’t make any changes in structure of
table.

SELECT <fieldname, fieldname, calculation >


FROM <tablename>

SELECT <fieldname, fieldname, calculation >


FROM <tablename> WHERE <expression>
Commands
Ex – SELECT name,clas, hindi, eng, sci, math,
(hindi+eng+sci+math> FROM pupil;
Commands
Ex – SELECT name,clas, hindi, eng, sci, math,
(hindi+eng+sci+math> FROM pupil WHERE
gnd=‘Female’;
Commands
User can also perform provide the alias name
to the fields (columns) on temporary basis for
display purpose only.

SELECT <fieldname AS aliasname, calculation


as aliasname> FROM <tablename>

SELECT <fieldname AS aliasname, calculation


as aliasname> FROM <tablename> WHERE
<expression>
Commands
Ex – SELECT name AS Stud_Name, hindi AS HINDI,
eng AS ENGLISH, sci AS SCIENCE, math as MATH
FROM pupil;
Commands
Ex– SELECT name AS Stud_Name, clas AS Class, sec
AS Section, hindi+eng+sci+math AS Total FROM
pupil;
Commands
Ex– SELECT name AS Stud_Name, hindi+ eng+ sci+
math AS Total, (hindi + eng + sci + math)/4 AS
Percent FROM pupil;
Commands
Ex– SELECT name AS Stud_Name, (hindi + eng + sci
+ math)/4 AS Percent FROM pupil WHERE (hindi
+eng+ sci + math)/4 >=60;
Commands
User can also perform calculations in the
query but that is only for display purpose, it
doesn’t make any changes in structure of
table.

SELECT <fieldname, fieldname, calculation >


FROM <tablename>

SELECT <fieldname, fieldname, calculation >


FROM <tablename> WHERE <expression>
Commands
Ex – SELECT name,clas, hindi, eng, sci, math,
(hindi+eng+sci+math> FROM pupil;
Commands
Ex – SELECT name,clas, hindi, eng, sci, math,
(hindi+eng+sci+math> FROM pupil WHERE
gnd=‘Female’;
Commands
User can also perform provide the alias name
to the fields (columns) on temporary basis for
display purpose only.

SELECT <fieldname AS aliasname, calculation


as aliasname> FROM <tablename>

SELECT <fieldname AS aliasname, calculation


as aliasname> FROM <tablename> WHERE
<expression>
Commands
Ex – SELECT name AS Stud_Name, hindi AS HINDI,
eng AS ENGLISH, sci AS SCIENCE, math as MATH
FROM pupil;
Commands
Ex– SELECT name AS Stud_Name, clas AS Class, sec
AS Section, hindi+eng+sci+math AS Total FROM
pupil;
Commands
Ex– SELECT name AS Stud_Name, hindi+ eng+ sci+
math AS Total, (hindi + eng + sci + math)/4 AS
Percent FROM pupil;
Commands
Ex– SELECT name AS Stud_Name, (hindi + eng + sci
+ math)/4 AS Percent FROM pupil WHERE (hindi
+eng+ sci + math)/4 >=60;
Distinct
DISTINCT – Display the uniques records from
table.
SELECT DISTINCT(<field>) FROM <tablename>
Ex- SELECT DISTINCT(clas) FROM pupil;
Order By
ORDER BY -To display the records in arranged
manner, either in ascending or in descending
order.
SELECT * FROM <tablename> ORDER BY
<fieldname>

Ex – SELECT * FROM pupil ORDER BY class;


Commands

As you can see, all records get arranged according


to class in ascending order.
Commands
SELECT * FROM <tablename> ORDER BY
<fieldname>, <fieldname>
We can arrange the records on the basis of 2 or
more than 2 field.
Commands
To display the values in descending order.
Ex- SELECT * FROM pupil ORDER BY gnd, clas
DESC;
Commands
We can also provide the conditions while
arranging the records.
Ex- SELECT * FROM pupil WHERE gnd=‘Female’
ORDER BY name;
Aggregate Functions
To apply the fucntion to get the collective results
from the records of table, one can use aggregate
fucntions.
SELECT function <fieldname> FROM <tablename>
SUM() – Return the sum of values of specified field.
AVG() – Return the average of values of specified
field.
MAX() – Return the largest value of specified field.
MIN() – Return the smallest value of specified field.
COUNT() – Return the count of values specified for
given value.
Aggregate Functions
Ex- SELECT SUM(math) FROM pupil;

Ex – SELECT SUM(hindi),AVG(hindi) FROM pupil;


Aggregate Functions
Ex- SELECT MAX(hindi), MAX(eng), MAX(sci),
MAX(math) FROM pupil;

Ex – SELECT MIN(hindi), MIN(eng), MIN(sci),


MIN(math) FROM pupil;
Aggregate Functions
Ex – SELECT COUNT(*) FROM pupil WHERE
gnd=‘Male’;

Ex– SELECT COUNT(*) FROM pupil WHERE clas<>9;


Commands
Ex – SELECT COUNT(clas) FROM pupil;

Aggregate function works on entire table. What


if? We want to display the count of each class.
GROUP BY – Perform the aggregate function on
the groups and provide aggregate results.
SELECT function <fieldname> FROM
<tablename> GROUP BY <fieldname>
Commands
Ex – SELECT clas, COUNT(clas) FROM pupil
GROUP BY clas;

It will display the class along with its counting.


Table should be grouped on that field on which
we want to group the table.
Commands
Ex – SELECT gnd, COUNT(gnd) FROM pupil GROUP
BY gnd;

Ex- SELECT clas, avg(math) FROM pupil GROUP BY


clas;

.
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;

Now there is changes in record no. 3


Commands
UPDATE <tablename> SET <field> = <value>,
<field>=<value> WHERE <expression>
Ex- UPDATE record SET clas=10, sec=‘B’ WHERE
sno=6;
Commands
Going to update this table, field hindi.
Providing +10 marks in hindi for Male candidates.
Commands
Ex- UPDATE pupil SET hindi=50;
As you can see changes made to all records;
Commands
Ex- UPDATE pupil SET hindi=hindi+10 WHERE
gnd=‘Male’;
It will give +10 marks in hindi to Male students.
Commands
DELETE : Get used to delete the records from
existing record.
DELETE FROM <tablename>

Ex- DELETE FROM record;


It will delete all records from table but the
structure remains as it is. We can insert more
records in the structure.

We will try it later because it delete all the


records of specified table.
Commands

From this table, we are going to delete records.


Commands
Ex- DELETE FROM record WHERE clas<10;
It will delete all those records, which have class
less than 10.
Commands
Ex- DELETE FROM record WHERE gnd=‘Male’;
It will delete all those records, which have
gender as Male.
Commands
Ex- DELETE FROM record WHERE sec IS NULL;
To delete records related to NULL values, we can
mention IS NULL or NOT NULL in queries.
Commands
Ex- DELETE FROM record;
This will delete all records, leaves the structure
behind.

Here is the structure of table record.


Commands
TRUNCATE <tablename>
It will delete all records and leave the structure as
it is. We can not provide any conditions to it.
Ex- TRUNCATE record;
Commands
DROP : Get used to delete entire table. Its
records and structure too.
DROP TABLE <tablename>
Ex- DROP TABLE record;

Before After
Commands
This is the structure of table record.

What if, i want to add columns (field) in the table.


I want to delete any column(field) or to change
the datatype of any column.
Commands
ALTER
ALTER is the command, get used to make
changes in the structure in table. Keep in mind to
make changes in the existing records, we use
UPDATE.
ALTER TABLE <tablename> ADD/MODIFY/DROP
<expression>

To add a column (field) in the existing table


ALTER TABLE <tablename> ADD <columnname
datatype>
Commands
Ex- ALTER TABLE record ADD city varchar(30);

As you can see, a column city is added in table.


Commands
To make changes in datatype of any existing
column (field)
ALTER TABLE <tablename> MODIFY
<columnname new datatype>

As i want to change city from varchar(30) to


varchar(50).
Commands
Ex – ALTER TABLE record MODIFY city
varchar(50);

As you can see varchar(50) is assigned to city.


Commands
To store the values for field city, user have to use
UPDATE command.
Commands
To delete the existing column (field) from table
ALTER TABLE <tablename> DROP COLUMN
<columnname>
If i want to delete the newly added column city
from the table record.

Ex- ALTER TABLE record DROP COLUMN city;

It will drop/delete the specified column from the


table.
Commands

There is no field called city in the above table.


SQL Constraints
Constraints are Data Validations or you can say
checking, which system makes while entering the
data. We have already learnt about following
constraints - PRIMARY KEY, and UNIQUE
DEFAULT : Can set default value for any field (column).
AUTO_INCREMENT : Set the filed to increment it's
value automatically.
NOT NULL: Make entry mandatory for particular field.
CHECK: Can set checking for any field.
One can set these constraint at the time of table
creation and can also set by command ALTER.
DEFAULT
The DEFAULT constraint is used to provide a default
value for a column.
The default value will be added to all new records IF no
other value is specified.
To create table
Syntax
CREATE TABLE <tablename> (field datatype , field
datatype default ‘value’, ……)
DEFAULT

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

By default, a column can hold NULL values.


The NOT NULL constraint enforces a column to NOT
accept NULL values.
This enforces a field to always contain a value, which
means that you cannot insert a new record, or update
a record without adding a value to this field.
To Create table
Syntax
CREATE TABLE <tablename> (field datatype, field
datyatype NOT NULL)
NOT NULL
As we
see ,
NULL is
stored in
Rno, when-
ever
we skip the
Entries, NULL
get stored.
NOT NULL

As we see, NULL is not permitted in field called name.


NOT NULL

ALTER TABLE MODIFY name varchar (20) NOT NULL


Check
The CHECK constraint is used to limit the value range
that can be placed in a column.
If you define a CHECK constraint on a single column it
allows only certain values for this column.
If you define a CHECK constraint on a table it can limit
the values in certain columns based on values in other
columns in the row.
To Create table
Syntax
CREATE TABLE <tablename> (field datatype, field
datyatype CHECK (expression))
Check

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- Key using which relationship


between two tables get established.
RDBMS
RDBMS
In table personal, rno is a primary key and in table
marks it is treated as foriegn key, through which
two tables get connected.
RDBMS

Can anyone tell me which are the marks of


student Hiten and which are of Pooja?
Primary Key
RDBMS

Primary Key establish


a connection in
another table as
Foriegn key.

Foreign Key

Now you can figure


out the marks of
Hiten and Pooja.
RDBMS
What if, we want to view records of both tables
simultaneously.

SELECT <tablename.fieldname, fieldname,


fieldname> FROM <table 1, table 2) WHERE
<table1.primary key=table2.foriegn key>

Though both tables have same key as primary


and foreign. So we have to mention table name
to avoid confusion regarding field from which
table.
RDBMS
SELECT personal.rno, name, exam, hindi, eng
FROM personal, marks WHERE personal.rno
=marks.rno;
RDBMS
What if, we want to view records of both tables
simultaneously.

SELECT <tablename1.fieldname, fieldname,


fieldname> FROM <table 1 tablename1, table 2
tablename2> WHERE <tablename1.primary
key=tablename2.foriegn key>
Though both tables have same key as primary
and foreign. So we have to mention table name
to avoid confusion regarding field from which
table.
RDBMS

SELECT P.rno, name, exam, hindi, eng FROM


personal P, marks M WHERE P.rno =M.rno;

Though both tables have same key as primary


and foreign. So we have to mention alias table
name to avoid confusion regarding field from
which table.
RDBMS
We can also put conditions in this too.
SELECT personal.rno, name, exam, hindi, eng
FROM personal, marks WHERE personal.rno
=marks.rno and sec=‘A’;
RDBMS

We have a file to solve some queries.

D:\2021-2022\Content\12th Common\To
Try.pdf
Thank You

You might also like