SlideShare a Scribd company logo
Unit-III
DATABASES MANAGEMENT SYSTEM AND SQL
DBMS & Structured Query Language Chapter: 07
Basic Database concepts
Data : Raw facts and figures which are useful to an organization. We cannot take decisions on the
basis of data.
Information: Well processed data is called information. We can take decisions on the basis of
information
Field: Set of characters that represents specific data element.
Record: Collection of fields is called a record. A record can have fields of different datatypes.
File: Collection of similar types of records is called a file.
Table: Collection of rows and columns that contains useful data/information is called a table. A table
generally refers to the passive entity which is kept in secondary storage device.
Relation: Relation (collection of rows and columns) generally refers to an active entity on which we
can perform various operations.
Database: Collection of logically related data along with its description is termed as database.
Tuple: A row in a relation is called a tuple.
Attribute: A column in a relation is called an attribute. It is also termed as field or data item.
Degree: Number of attributes in a relation is called degree of a relation.
Cardinality: Number of tuples in a relation is called cardinality of a relation.
Primary Key: Primary key is a key that can uniquely identifies the records/tuples in a relation. This
key can never be duplicated and NULL.
Foreign Key: Non key attribute of a table acting as primary key in some other table is known as
Foreign Key in its current table. This key is used to enforce referential integrity in RDBMS.
Candidate Key: Attributes of a table which can serve as a primary key are called candidate key.
Alternate Key: All the candidate keys other than the primary keys of a relation are alternate keys for
a relation.
DBA: Data Base Administrator is a person (manager) that is responsible for defining the data base
schema, setting security features in database, ensuring proper functioning of the data bases etc.
Select Operation: The select operation selects tuples from a relation which satisfy a given condition.
Project Operation: The project operation selects columns from a relation which satisfy a given
all available columns.
Union Operation: The union (denoted as ) of a collection of relations is the set of all distinct
tuples in the collection. It is a binary operation that needs two relations.
Set Difference Operation: This is denoted by (minus) and is a binary operation. It results in a set
of tuples that are in one relation but not in another
Structured Query Language
SQL is a non procedural language that is used to create, manipulate and process the
databases(relations).
1. Data Definition Language (DDL)
DDL contains commands that are used to create the tables, databases, indexes, views, sequences and
synonyms etc.
e.g: Create table, create view, create index, alter table etc.
45
46
2. Data Manipulation Language (DML)
DML contains commands that can be used to manipulate the data base objects and to query the
databases for information retrieval.
e.g Select, Insert, Delete, Update etc.
3. Transaction Control Language (TCL)
TCL include commands to control the transactions in a data base system. The commonly
used commands in TCL are COMMIT, ROLLBACK etc.
Operators in SQL: The following are the commonly used operators in SQL
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
+, -, *, /
=, <, >, <=, >=, <>
OR, AND, NOT
Data types of SQL: Just like any other programming language, the facility of defining data
of various types is available in SQL also. Following are the most common data types of SQL.
1) NUMBER
2) CHAR
e.g. Number(n,d) Number (5,2)
CAHR(SIZE)
3) VARCHAR / VARCHAR2 VARCHAR2(SIZE)
4) DATE DD-MON-YYYY
Constraints: Constraints are the conditions that can be enforced on the attributes of a relation.
The constraints come in play when ever we are trying to insert, delete or update a record in a
relation.
Not null ensures that we cannot leave a column as null. That is a value has to be supplied for that
column.
e.g. name varchar(25) not null
Unique constraint means that the values under that column are always unique.
e.g. Roll_no number(3) unique
Primary key constraint means that a column can not have duplicate values and not even a null value.
e.g. Roll_no number(3) primary key
The main difference between unique and primary key constraint is that a column specified as unique
may have null value but primary key constraint does not allow null values in the column.
Foreign key is used to enforce referential integrity and is declared as a primary key in some other
table.
e.g. cust_id varchar(5) references master(cust_id)
it declares cust_id column as a foreign key that refers to cust_id field of table master.
That means we cannot insert that value in cust_id filed whose corresponding value is not present in
cust_id field of master table. master table , if a corresponding
value of cust_id field is existing in the dependent table.
Check constraint limits the values that can be inserted into a column of a table.
e.g. marks number(3) check(marks>=0)
The above statement declares marks to be of type number and while inserting or updating the value
in marks it is ensured that its value is always greater than or equal to zero.
Default constraint is used to specify a default value to a column of a table automatically. This default
value will be used when user does not enter any value for that column.
e.g. balance number(5) default = 0
1.
SQL COMMANDS :
Create Table command is used to create a table . The syntax of this Command is:
CREATE TABLE <Table_name>
data_type1 [(size) column_constraints],
data_type1 [(size) column_constraints],
( column_name 1
column_name 1
:
:
[<table_constraint> (column_names)] );
2.The ALTER Table command is used to change the definition (structure) of existing table.
ALTER TABLE <Table_name> ADD/MODIFY <Column_defnition>; For Add or modify column
ALTER TABLE <Table_name> DROP COLUMN <Column_name>; For Deleting a column
3. The INSERT Command: The rows (tuples) are added to a table by using INSERT command.
The syntax of Insert command is:
INSERT INTO <table_name> [(<column_list>)] VALUES (<value_list>);
e.g.,
INSERT INTO EMP (empno, ename,
If the order of values matches the actual order of columns in table then it is not required to give the
column_list in INSERT command. e.g.
4. The Update command is used to change the value in a table. The syntax of this command is:
UPDATE <table_name>
SET column_name1=newvalue1/expression [,column_name2=newvalue2/expression
WHERE <condition>;
e.g., to increase the salary of all the employees of department No 10 by 10% , then command will
be:
UPDATE emp
SET sal=sal*1.1
WHERE Deptno=10;
5. The DELETE command removes rows from a table. This removes the entire rows, not
individual field values. The syntax of this command is
DELETE FROM <table_name>
[WHERE <condition>];
e.g., to delete the tuples from EMP that have salary less than 2000, the following command is used:
DELETE FROM emp WHERE sal<2000;
To delete all tuples from emp table:
DELETE FROM emp;
6. The SELECT command is used to make queries on database. A query is a command that is given
to produce certain specified information from the database table(s). The SELECT command can be
used to retrieve a subset of rows or columns from one or more tables. The syntax of Select Command
is:
SELECT <Column-list>
FROM <table_name>
[WHERE <condition>]
[GROUP BY <column_list>]
[HAVING <condition>]
[ORDER BY <column_list [ASC|DESC ]>]
The select clause list the attributes desired in the result of a query.
e.g.,To display the names of all Employees in the emp relation:
select ename from emp;
To force the elimination of duplicates, insert the keyword distinct after select.
Find the number of all departments in the emp relations, and remove duplicates
select distinct deptno from emp;
47
An asterisk (*)
SELECT * FROM emp;
The select clause can contain arithmetic expressions involving the operation, +, , *, and /, and
operating on constants or attributes of tuples. The query:
SELECT empno, ename, sal * 12 FROM emp;
would display all values same as in the emp relation, except that the value of the attribute sal is
multiplied by 12.
The WHERE clause in SELECT statement specifies the criteria for selection of rows to be returned.
Conditions based on a range (BETWEEN Operator): The Between operator defines a range
of values that the column values must fall in to make condition true . The range includes both lower
value and upper value.
e.g., Find the empno of those employees whose salary between 90,000 and 100,000 (that is, 90,000
and 100,000)
SELECT empno FROM emp WHERE sal BETWEEN 90000 AND 100000;
Conditions based on a list (IN operator): To specify a list of values , IN operator is used. IN
operator selects values that match any value in a given list of values.
The NOT IN operator finds rows that do not match in the list. So if you write
It will list members not from the cities mentioned in the list.
Conditions based on Pattern: SQL also includes a string-matching operator, LIKE, for
comparison on character string using patterns. Patterns are described using two special wildcard
characters:
Percent (%)
Underscore (_)
% matches any substring(one,more than one or no character).
character.
Patterns are case-senstive.
Like keyword is used to select row contaning columns that match a wildcard pattern.
The keyword not like is used to select the row that do not match the specified patterns
of characters.
Searching for NULL: The NULL value in a column is searched for in a table using IS NULL in
the WHERE clause (Relational Operators like =,<> etc can not be used with NULL).
For example, to list details of all employees whose departments contain NULL (i.e., novalue), you
use the command:
SELECT empno, ename FROM emp Where Deptno IS NULL;
ORDER BY Clause: Whenever a select query is executed the resulting rows are displayed in the
order in which the exist in the table. You can sort the result of a query in a specific order using
ORDER BY clause. The ORDER BY clause allow sorting of query result by one or more
columns. The sorting can be done either in ascending or descending order.
Note:- If order is not specifies that by default the sorting will be performed in ascendingorder.
GROUP BY Clause: The GROUP BY clause groups the rows in the result by columns that have
the same values. Grouping is done on column name. It can also be performed using aggregate
functions in which case the aggregate function produces single value for each group.
Aggregate Functions: These functions operate on the multiset of values of a column of a relation,
and return a value
avg: average value
min: minimum value
max: maximum value
sum: sum of values
count: number of values
48
Ans : (i) SELECT GameName,Gcode FROM GAMES;
(ii) SELECT * FROM GAMES WHERE PrizeMoney>7000;
(iii) SELECT * FROM GAMES ORDER BY ScheduleDate;
49
These functions are called aggregate functions because they operate on aggregates of tuples. The
result of an aggregate function is a single value.
HAVING Clause: The HAVING clause place conditions on groups in contrast to WHERE clause
that place conditions on individual rows. While WHERE condition cannot include aggregate
functions, HAVING conditions can do so. e.g.,
Select avg(sal), sum(sal) from emp group by deptno having deptno=10;
Select job, count(*) from emp group by job having count(*)<3;
7. The DROP Command : The DROP TABLE command is used to drop (delete) a table from
database. But there is a condition for droping a table ; it must be an empty table i.e. a table with rows
in it cannot be dropped.The syntax of this command is :
DROP TABLE <Table_name>;
e.g.,
DROP TABLE EMP;
8. Query Based on Two table (Join):
SELECT <Column-list>
FROM <table_name1>,<table_name2>
WHERE <Join_condition>[AND condition];
9. Qualified Names :
<tablename>.<fieldname>
This type of field names are called qualified field names and are used to identifying a field if the two
joining tables have fields with same name.
6 Marks Questions
Q2. Consider the following tables GAMES and PLAYER. Write SQL commands for the statements
(i) to (iv) and give outputs for SQL queries (v) to (viii).
Table: GAMES
GCode GameName Number PrizeMoney ScheduleDate
101 Carom Board 2 5000 23-Jan-2004
102 Badminton 2 12000 12-Dec-2003
103 Table Tennis 4 8000 14-Feb-2004
105 Chess 2 9000 01-Jan-2004
108 Lawn Tennis 4 25000 19-Mar-2004
Table: PLAYER
PCode Name Gcode
1 Nabi Ahmad 101
2 Ravi Sahai 108
3 Jatin 101
4 Nazneen 103
(i)
(ii)
(iii)
(iv)
To display the name of all Games with their Gcodes.
To display details of those games which are having PrizeMoney more than 7000.
To display the content of the GAMES table in ascending order of ScheduleDate.
To display sum of PrizeMoney for each of the Number of participation groupings (as shown
in column Number 2 or 4).
SELECT COUNT(DISTINCT Number) FROM GAMES;
SELECT MAX(ScheduleDate),MIN(ScheduleDate) FROM GAMES;
SELECT SUM(PrizeMoney) FROM GAMES;
SELECT DISTINCT Gcode FROM PLAYER;
(v)
(vi)
(vii)
(viii)
50
(iv) SELECT SUM(PrizeMoney),Number FROM GAMES GROUP BY Number;
(v) 2
(vi) 19-Mar-2004 12-Dec-2003
(vii) 59000
(viii) 101
103
108
Q2. Consider the following tables FACULTY and COURSES. Write SQL commands for the
statements (i) to (v) and give outputs for SQL queries (vi) to (vii).
FACULTY
F_ID Fname Lname Hire_date Salary
102 Amit Mishra 12-10-1998 12000
103 Nitin Vyas 24-12-1994 8000
104 Rakshit Soni 18-5-2001 14000
105 Rashmi Malhotra 11-9-2004 11000
106 Sulekha Srivastava 5-6-2006 10000
COURSES
C_ID F_ID Cname Fees
C21 102 Grid Computing 40000
C22 106 System Design 16000
C23 104 Computer Security 8000
C24 106 Human Biology 15000
C25 102 Computer Network 20000
C26 105 Visual Basic 6000
i) To display details of those Faculties whose salary is greater than 12000.
ii)To display the details of courses whose fees is in the range of 15000 to 50000 (both
values included).
iv
courses.
v) Select COUNT(DISTINCT F_ID) from COURSES;
vi)Select Fname,Cname from FACULTY,COURSES where COURSES.F_ID =FACULTY.F_ID;
Ans.: (i) Select * from faculty where salary > 12000;
(ii) Select * from Courses.where fees between 15000 and 50000;
(iii)
(iv) Select * from faculty fac,courses cour where fac.f_id = cour.f_id and fac.fname =
'Sulekha' order by cname desc;
(v) 4
2- Marks Questions
Define the following terms:
(i) DDL (ii) DML (iii) Primary Key (iv) Candidate Key
(v) Alternet Key (vi) Foreign Key (vii) Cardinality of relation (viii) Degree of relation
(ix) Relation (x) Attribute (xi) Tuple
Fname Cname
Amit Grid Computing
Rakshit Computer Security
Rashmi Visual Basic
Sulekha Human Biology

More Related Content

What's hot (20)

Sql commands
Sql commandsSql commands
Sql commands
Mohd Tousif
 
Sql.pptx
Sql.pptxSql.pptx
Sql.pptx
TanishaKochak
 
SQL
SQLSQL
SQL
Tuhin_Das
 
Sql commands
Sql commandsSql commands
Sql commands
Balakumaran Arunachalam
 
Mysql
MysqlMysql
Mysql
TSUBHASHRI
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
Nishant Munjal
 
Sql slid
Sql slidSql slid
Sql slid
pacatarpit
 
SQL
SQLSQL
SQL
Vineeta Garg
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
Abdelhay Shafi
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
TechandMate
 
Sql select
Sql select Sql select
Sql select
Mudasir Syed
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
Stewart Rogers
 
A must Sql notes for beginners
A must Sql notes for beginnersA must Sql notes for beginners
A must Sql notes for beginners
Ram Sagar Mourya
 
SQL commands
SQL commandsSQL commands
SQL commands
GirdharRatne
 
SQL
SQLSQL
SQL
zekeLabs Technologies
 
MS SQL Server 1
MS SQL Server 1MS SQL Server 1
MS SQL Server 1
Iblesoft
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
Swapnali Pawar
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
HudaRaghibKadhim
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
Mohd Tousif
 

Similar to DATABASE MANAGMENT SYSTEM (DBMS) AND SQL (20)

ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsgADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
zmulani8
 
Class XII-UNIT III - SQL and MySQL Notes_0.pdf
Class XII-UNIT III - SQL and MySQL Notes_0.pdfClass XII-UNIT III - SQL and MySQL Notes_0.pdf
Class XII-UNIT III - SQL and MySQL Notes_0.pdf
rohithlingineni1
 
Dbms sql-final
Dbms  sql-finalDbms  sql-final
Dbms sql-final
NV Chandra Sekhar Nittala
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
sagaroceanic11
 
Oracle
OracleOracle
Oracle
Rajeev Uppala
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptx
PriyaPandey767008
 
MY SQL
MY SQLMY SQL
MY SQL
sundar
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
Sherif Gad
 
SQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATION
SQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATIONSQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATION
SQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATION
deeptanshudas100
 
Sql
SqlSql
Sql
Diana Diana
 
Introduction to SQL..pdf
Introduction to SQL..pdfIntroduction to SQL..pdf
Introduction to SQL..pdf
mayurisonawane29
 
sql_data.pdf
sql_data.pdfsql_data.pdf
sql_data.pdf
VandanaGoyal21
 
chapter9-SQL.pptx
chapter9-SQL.pptxchapter9-SQL.pptx
chapter9-SQL.pptx
Yaser52
 
12 SQL
12 SQL12 SQL
12 SQL
Praveen M Jigajinni
 
12 SQL
12 SQL12 SQL
12 SQL
Praveen M Jigajinni
 
Database Akjljljlkjlkjkljlkjldiministration.pptx
Database Akjljljlkjlkjkljlkjldiministration.pptxDatabase Akjljljlkjlkjkljlkjldiministration.pptx
Database Akjljljlkjlkjkljlkjldiministration.pptx
EliasPetros
 
SQL
SQLSQL
SQL
Mohamed Essam
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
Sachidananda M H
 
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
SAMPLE QUESTION PAPER (THEORY)  CLASS: XII SESSION: 2024-25  COMPUTER SCIENCE...SAMPLE QUESTION PAPER (THEORY)  CLASS: XII SESSION: 2024-25  COMPUTER SCIENCE...
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
MafnithaKK
 
SQL.pptx SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTE...
SQL.pptx SAMPLE QUESTION PAPER (THEORY)  CLASS: XII SESSION: 2024-25  COMPUTE...SQL.pptx SAMPLE QUESTION PAPER (THEORY)  CLASS: XII SESSION: 2024-25  COMPUTE...
SQL.pptx SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTE...
MafnithaKK
 
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsgADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
zmulani8
 
Class XII-UNIT III - SQL and MySQL Notes_0.pdf
Class XII-UNIT III - SQL and MySQL Notes_0.pdfClass XII-UNIT III - SQL and MySQL Notes_0.pdf
Class XII-UNIT III - SQL and MySQL Notes_0.pdf
rohithlingineni1
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
sagaroceanic11
 
SQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATION
SQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATIONSQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATION
SQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATION
deeptanshudas100
 
chapter9-SQL.pptx
chapter9-SQL.pptxchapter9-SQL.pptx
chapter9-SQL.pptx
Yaser52
 
Database Akjljljlkjlkjkljlkjldiministration.pptx
Database Akjljljlkjlkjkljlkjldiministration.pptxDatabase Akjljljlkjlkjkljlkjldiministration.pptx
Database Akjljljlkjlkjkljlkjldiministration.pptx
EliasPetros
 
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
SAMPLE QUESTION PAPER (THEORY)  CLASS: XII SESSION: 2024-25  COMPUTER SCIENCE...SAMPLE QUESTION PAPER (THEORY)  CLASS: XII SESSION: 2024-25  COMPUTER SCIENCE...
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
MafnithaKK
 
SQL.pptx SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTE...
SQL.pptx SAMPLE QUESTION PAPER (THEORY)  CLASS: XII SESSION: 2024-25  COMPUTE...SQL.pptx SAMPLE QUESTION PAPER (THEORY)  CLASS: XII SESSION: 2024-25  COMPUTE...
SQL.pptx SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTE...
MafnithaKK
 
Ad

More from Dev Chauhan (17)

GTU induction program report
GTU induction program report GTU induction program report
GTU induction program report
Dev Chauhan
 
2 States Book Review
2 States Book Review2 States Book Review
2 States Book Review
Dev Chauhan
 
STACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUESTACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUE
Dev Chauhan
 
NETWORKING AND COMMUNICATION TECHNOLOGIES
NETWORKING AND COMMUNICATION TECHNOLOGIESNETWORKING AND COMMUNICATION TECHNOLOGIES
NETWORKING AND COMMUNICATION TECHNOLOGIES
Dev Chauhan
 
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
Dev Chauhan
 
BASIC CONCEPTS OF C++ CLASS 12
BASIC CONCEPTS OF C++ CLASS 12BASIC CONCEPTS OF C++ CLASS 12
BASIC CONCEPTS OF C++ CLASS 12
Dev Chauhan
 
BOOLEAN ALGEBRA
BOOLEAN ALGEBRABOOLEAN ALGEBRA
BOOLEAN ALGEBRA
Dev Chauhan
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++
Dev Chauhan
 
Communication and Network Concepts
Communication and Network ConceptsCommunication and Network Concepts
Communication and Network Concepts
Dev Chauhan
 
What is bullying
What is bullyingWhat is bullying
What is bullying
Dev Chauhan
 
Properties Of Water
Properties Of WaterProperties Of Water
Properties Of Water
Dev Chauhan
 
बहुव्रीहि समास
बहुव्रीहि समासबहुव्रीहि समास
बहुव्रीहि समास
Dev Chauhan
 
अव्ययीभाव समास
अव्ययीभाव समासअव्ययीभाव समास
अव्ययीभाव समास
Dev Chauhan
 
तत्पुरुष (विभक्ति, उपपद ऽ नञ्)
तत्पुरुष (विभक्ति, उपपद ऽ नञ्)तत्पुरुष (विभक्ति, उपपद ऽ नञ्)
तत्पुरुष (विभक्ति, उपपद ऽ नञ्)
Dev Chauhan
 
कर्मधारय, द्विगु समास
कर्मधारय, द्विगु समासकर्मधारय, द्विगु समास
कर्मधारय, द्विगु समास
Dev Chauhan
 
द्वन्द्व समास
द्वन्द्व समासद्वन्द्व समास
द्वन्द्व समास
Dev Chauhan
 
Class 10 Farewell Presentation Topic:- Nostalgia
Class 10 Farewell Presentation Topic:- NostalgiaClass 10 Farewell Presentation Topic:- Nostalgia
Class 10 Farewell Presentation Topic:- Nostalgia
Dev Chauhan
 
GTU induction program report
GTU induction program report GTU induction program report
GTU induction program report
Dev Chauhan
 
2 States Book Review
2 States Book Review2 States Book Review
2 States Book Review
Dev Chauhan
 
STACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUESTACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUE
Dev Chauhan
 
NETWORKING AND COMMUNICATION TECHNOLOGIES
NETWORKING AND COMMUNICATION TECHNOLOGIESNETWORKING AND COMMUNICATION TECHNOLOGIES
NETWORKING AND COMMUNICATION TECHNOLOGIES
Dev Chauhan
 
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
Dev Chauhan
 
BASIC CONCEPTS OF C++ CLASS 12
BASIC CONCEPTS OF C++ CLASS 12BASIC CONCEPTS OF C++ CLASS 12
BASIC CONCEPTS OF C++ CLASS 12
Dev Chauhan
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++
Dev Chauhan
 
Communication and Network Concepts
Communication and Network ConceptsCommunication and Network Concepts
Communication and Network Concepts
Dev Chauhan
 
What is bullying
What is bullyingWhat is bullying
What is bullying
Dev Chauhan
 
Properties Of Water
Properties Of WaterProperties Of Water
Properties Of Water
Dev Chauhan
 
बहुव्रीहि समास
बहुव्रीहि समासबहुव्रीहि समास
बहुव्रीहि समास
Dev Chauhan
 
अव्ययीभाव समास
अव्ययीभाव समासअव्ययीभाव समास
अव्ययीभाव समास
Dev Chauhan
 
तत्पुरुष (विभक्ति, उपपद ऽ नञ्)
तत्पुरुष (विभक्ति, उपपद ऽ नञ्)तत्पुरुष (विभक्ति, उपपद ऽ नञ्)
तत्पुरुष (विभक्ति, उपपद ऽ नञ्)
Dev Chauhan
 
कर्मधारय, द्विगु समास
कर्मधारय, द्विगु समासकर्मधारय, द्विगु समास
कर्मधारय, द्विगु समास
Dev Chauhan
 
द्वन्द्व समास
द्वन्द्व समासद्वन्द्व समास
द्वन्द्व समास
Dev Chauhan
 
Class 10 Farewell Presentation Topic:- Nostalgia
Class 10 Farewell Presentation Topic:- NostalgiaClass 10 Farewell Presentation Topic:- Nostalgia
Class 10 Farewell Presentation Topic:- Nostalgia
Dev Chauhan
 
Ad

Recently uploaded (20)

Revista digital preescolar en transformación
Revista digital preescolar en transformaciónRevista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POSHow to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
Publishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke WarnerPublishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke Warner
Brooke Warner
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptxWhat is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptxRai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle SchoolExploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
BINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptxBINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptx
Ramakrishna Reddy Bijjam
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo SlidesOverview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 EmployeesOverview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Revista digital preescolar en transformación
Revista digital preescolar en transformaciónRevista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POSHow to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
Publishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke WarnerPublishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke Warner
Brooke Warner
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptxWhat is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle SchoolExploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
BINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptxBINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptx
Ramakrishna Reddy Bijjam
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo SlidesOverview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 EmployeesOverview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 

DATABASE MANAGMENT SYSTEM (DBMS) AND SQL

  • 1. Unit-III DATABASES MANAGEMENT SYSTEM AND SQL DBMS & Structured Query Language Chapter: 07 Basic Database concepts Data : Raw facts and figures which are useful to an organization. We cannot take decisions on the basis of data. Information: Well processed data is called information. We can take decisions on the basis of information Field: Set of characters that represents specific data element. Record: Collection of fields is called a record. A record can have fields of different datatypes. File: Collection of similar types of records is called a file. Table: Collection of rows and columns that contains useful data/information is called a table. A table generally refers to the passive entity which is kept in secondary storage device. Relation: Relation (collection of rows and columns) generally refers to an active entity on which we can perform various operations. Database: Collection of logically related data along with its description is termed as database. Tuple: A row in a relation is called a tuple. Attribute: A column in a relation is called an attribute. It is also termed as field or data item. Degree: Number of attributes in a relation is called degree of a relation. Cardinality: Number of tuples in a relation is called cardinality of a relation. Primary Key: Primary key is a key that can uniquely identifies the records/tuples in a relation. This key can never be duplicated and NULL. Foreign Key: Non key attribute of a table acting as primary key in some other table is known as Foreign Key in its current table. This key is used to enforce referential integrity in RDBMS. Candidate Key: Attributes of a table which can serve as a primary key are called candidate key. Alternate Key: All the candidate keys other than the primary keys of a relation are alternate keys for a relation. DBA: Data Base Administrator is a person (manager) that is responsible for defining the data base schema, setting security features in database, ensuring proper functioning of the data bases etc. Select Operation: The select operation selects tuples from a relation which satisfy a given condition. Project Operation: The project operation selects columns from a relation which satisfy a given all available columns. Union Operation: The union (denoted as ) of a collection of relations is the set of all distinct tuples in the collection. It is a binary operation that needs two relations. Set Difference Operation: This is denoted by (minus) and is a binary operation. It results in a set of tuples that are in one relation but not in another Structured Query Language SQL is a non procedural language that is used to create, manipulate and process the databases(relations). 1. Data Definition Language (DDL) DDL contains commands that are used to create the tables, databases, indexes, views, sequences and synonyms etc. e.g: Create table, create view, create index, alter table etc. 45
  • 2. 46 2. Data Manipulation Language (DML) DML contains commands that can be used to manipulate the data base objects and to query the databases for information retrieval. e.g Select, Insert, Delete, Update etc. 3. Transaction Control Language (TCL) TCL include commands to control the transactions in a data base system. The commonly used commands in TCL are COMMIT, ROLLBACK etc. Operators in SQL: The following are the commonly used operators in SQL 1. Arithmetic Operators 2. Relational Operators 3. Logical Operators +, -, *, / =, <, >, <=, >=, <> OR, AND, NOT Data types of SQL: Just like any other programming language, the facility of defining data of various types is available in SQL also. Following are the most common data types of SQL. 1) NUMBER 2) CHAR e.g. Number(n,d) Number (5,2) CAHR(SIZE) 3) VARCHAR / VARCHAR2 VARCHAR2(SIZE) 4) DATE DD-MON-YYYY Constraints: Constraints are the conditions that can be enforced on the attributes of a relation. The constraints come in play when ever we are trying to insert, delete or update a record in a relation. Not null ensures that we cannot leave a column as null. That is a value has to be supplied for that column. e.g. name varchar(25) not null Unique constraint means that the values under that column are always unique. e.g. Roll_no number(3) unique Primary key constraint means that a column can not have duplicate values and not even a null value. e.g. Roll_no number(3) primary key The main difference between unique and primary key constraint is that a column specified as unique may have null value but primary key constraint does not allow null values in the column. Foreign key is used to enforce referential integrity and is declared as a primary key in some other table. e.g. cust_id varchar(5) references master(cust_id) it declares cust_id column as a foreign key that refers to cust_id field of table master. That means we cannot insert that value in cust_id filed whose corresponding value is not present in cust_id field of master table. master table , if a corresponding value of cust_id field is existing in the dependent table. Check constraint limits the values that can be inserted into a column of a table. e.g. marks number(3) check(marks>=0) The above statement declares marks to be of type number and while inserting or updating the value in marks it is ensured that its value is always greater than or equal to zero. Default constraint is used to specify a default value to a column of a table automatically. This default value will be used when user does not enter any value for that column. e.g. balance number(5) default = 0
  • 3. 1. SQL COMMANDS : Create Table command is used to create a table . The syntax of this Command is: CREATE TABLE <Table_name> data_type1 [(size) column_constraints], data_type1 [(size) column_constraints], ( column_name 1 column_name 1 : : [<table_constraint> (column_names)] ); 2.The ALTER Table command is used to change the definition (structure) of existing table. ALTER TABLE <Table_name> ADD/MODIFY <Column_defnition>; For Add or modify column ALTER TABLE <Table_name> DROP COLUMN <Column_name>; For Deleting a column 3. The INSERT Command: The rows (tuples) are added to a table by using INSERT command. The syntax of Insert command is: INSERT INTO <table_name> [(<column_list>)] VALUES (<value_list>); e.g., INSERT INTO EMP (empno, ename, If the order of values matches the actual order of columns in table then it is not required to give the column_list in INSERT command. e.g. 4. The Update command is used to change the value in a table. The syntax of this command is: UPDATE <table_name> SET column_name1=newvalue1/expression [,column_name2=newvalue2/expression WHERE <condition>; e.g., to increase the salary of all the employees of department No 10 by 10% , then command will be: UPDATE emp SET sal=sal*1.1 WHERE Deptno=10; 5. The DELETE command removes rows from a table. This removes the entire rows, not individual field values. The syntax of this command is DELETE FROM <table_name> [WHERE <condition>]; e.g., to delete the tuples from EMP that have salary less than 2000, the following command is used: DELETE FROM emp WHERE sal<2000; To delete all tuples from emp table: DELETE FROM emp; 6. The SELECT command is used to make queries on database. A query is a command that is given to produce certain specified information from the database table(s). The SELECT command can be used to retrieve a subset of rows or columns from one or more tables. The syntax of Select Command is: SELECT <Column-list> FROM <table_name> [WHERE <condition>] [GROUP BY <column_list>] [HAVING <condition>] [ORDER BY <column_list [ASC|DESC ]>] The select clause list the attributes desired in the result of a query. e.g.,To display the names of all Employees in the emp relation: select ename from emp; To force the elimination of duplicates, insert the keyword distinct after select. Find the number of all departments in the emp relations, and remove duplicates select distinct deptno from emp; 47
  • 4. An asterisk (*) SELECT * FROM emp; The select clause can contain arithmetic expressions involving the operation, +, , *, and /, and operating on constants or attributes of tuples. The query: SELECT empno, ename, sal * 12 FROM emp; would display all values same as in the emp relation, except that the value of the attribute sal is multiplied by 12. The WHERE clause in SELECT statement specifies the criteria for selection of rows to be returned. Conditions based on a range (BETWEEN Operator): The Between operator defines a range of values that the column values must fall in to make condition true . The range includes both lower value and upper value. e.g., Find the empno of those employees whose salary between 90,000 and 100,000 (that is, 90,000 and 100,000) SELECT empno FROM emp WHERE sal BETWEEN 90000 AND 100000; Conditions based on a list (IN operator): To specify a list of values , IN operator is used. IN operator selects values that match any value in a given list of values. The NOT IN operator finds rows that do not match in the list. So if you write It will list members not from the cities mentioned in the list. Conditions based on Pattern: SQL also includes a string-matching operator, LIKE, for comparison on character string using patterns. Patterns are described using two special wildcard characters: Percent (%) Underscore (_) % matches any substring(one,more than one or no character). character. Patterns are case-senstive. Like keyword is used to select row contaning columns that match a wildcard pattern. The keyword not like is used to select the row that do not match the specified patterns of characters. Searching for NULL: The NULL value in a column is searched for in a table using IS NULL in the WHERE clause (Relational Operators like =,<> etc can not be used with NULL). For example, to list details of all employees whose departments contain NULL (i.e., novalue), you use the command: SELECT empno, ename FROM emp Where Deptno IS NULL; ORDER BY Clause: Whenever a select query is executed the resulting rows are displayed in the order in which the exist in the table. You can sort the result of a query in a specific order using ORDER BY clause. The ORDER BY clause allow sorting of query result by one or more columns. The sorting can be done either in ascending or descending order. Note:- If order is not specifies that by default the sorting will be performed in ascendingorder. GROUP BY Clause: The GROUP BY clause groups the rows in the result by columns that have the same values. Grouping is done on column name. It can also be performed using aggregate functions in which case the aggregate function produces single value for each group. Aggregate Functions: These functions operate on the multiset of values of a column of a relation, and return a value avg: average value min: minimum value max: maximum value sum: sum of values count: number of values 48
  • 5. Ans : (i) SELECT GameName,Gcode FROM GAMES; (ii) SELECT * FROM GAMES WHERE PrizeMoney>7000; (iii) SELECT * FROM GAMES ORDER BY ScheduleDate; 49 These functions are called aggregate functions because they operate on aggregates of tuples. The result of an aggregate function is a single value. HAVING Clause: The HAVING clause place conditions on groups in contrast to WHERE clause that place conditions on individual rows. While WHERE condition cannot include aggregate functions, HAVING conditions can do so. e.g., Select avg(sal), sum(sal) from emp group by deptno having deptno=10; Select job, count(*) from emp group by job having count(*)<3; 7. The DROP Command : The DROP TABLE command is used to drop (delete) a table from database. But there is a condition for droping a table ; it must be an empty table i.e. a table with rows in it cannot be dropped.The syntax of this command is : DROP TABLE <Table_name>; e.g., DROP TABLE EMP; 8. Query Based on Two table (Join): SELECT <Column-list> FROM <table_name1>,<table_name2> WHERE <Join_condition>[AND condition]; 9. Qualified Names : <tablename>.<fieldname> This type of field names are called qualified field names and are used to identifying a field if the two joining tables have fields with same name. 6 Marks Questions Q2. Consider the following tables GAMES and PLAYER. Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii). Table: GAMES GCode GameName Number PrizeMoney ScheduleDate 101 Carom Board 2 5000 23-Jan-2004 102 Badminton 2 12000 12-Dec-2003 103 Table Tennis 4 8000 14-Feb-2004 105 Chess 2 9000 01-Jan-2004 108 Lawn Tennis 4 25000 19-Mar-2004 Table: PLAYER PCode Name Gcode 1 Nabi Ahmad 101 2 Ravi Sahai 108 3 Jatin 101 4 Nazneen 103 (i) (ii) (iii) (iv) To display the name of all Games with their Gcodes. To display details of those games which are having PrizeMoney more than 7000. To display the content of the GAMES table in ascending order of ScheduleDate. To display sum of PrizeMoney for each of the Number of participation groupings (as shown in column Number 2 or 4). SELECT COUNT(DISTINCT Number) FROM GAMES; SELECT MAX(ScheduleDate),MIN(ScheduleDate) FROM GAMES; SELECT SUM(PrizeMoney) FROM GAMES; SELECT DISTINCT Gcode FROM PLAYER; (v) (vi) (vii) (viii)
  • 6. 50 (iv) SELECT SUM(PrizeMoney),Number FROM GAMES GROUP BY Number; (v) 2 (vi) 19-Mar-2004 12-Dec-2003 (vii) 59000 (viii) 101 103 108 Q2. Consider the following tables FACULTY and COURSES. Write SQL commands for the statements (i) to (v) and give outputs for SQL queries (vi) to (vii). FACULTY F_ID Fname Lname Hire_date Salary 102 Amit Mishra 12-10-1998 12000 103 Nitin Vyas 24-12-1994 8000 104 Rakshit Soni 18-5-2001 14000 105 Rashmi Malhotra 11-9-2004 11000 106 Sulekha Srivastava 5-6-2006 10000 COURSES C_ID F_ID Cname Fees C21 102 Grid Computing 40000 C22 106 System Design 16000 C23 104 Computer Security 8000 C24 106 Human Biology 15000 C25 102 Computer Network 20000 C26 105 Visual Basic 6000 i) To display details of those Faculties whose salary is greater than 12000. ii)To display the details of courses whose fees is in the range of 15000 to 50000 (both values included). iv courses. v) Select COUNT(DISTINCT F_ID) from COURSES; vi)Select Fname,Cname from FACULTY,COURSES where COURSES.F_ID =FACULTY.F_ID; Ans.: (i) Select * from faculty where salary > 12000; (ii) Select * from Courses.where fees between 15000 and 50000; (iii) (iv) Select * from faculty fac,courses cour where fac.f_id = cour.f_id and fac.fname = 'Sulekha' order by cname desc; (v) 4 2- Marks Questions Define the following terms: (i) DDL (ii) DML (iii) Primary Key (iv) Candidate Key (v) Alternet Key (vi) Foreign Key (vii) Cardinality of relation (viii) Degree of relation (ix) Relation (x) Attribute (xi) Tuple Fname Cname Amit Grid Computing Rakshit Computer Security Rashmi Visual Basic Sulekha Human Biology