Practical File: Database Management System
Practical File: Database Management System
TECHNOLOGY
KURUKSHETRA, KURUKSHETRA UNIVERSITY
PRACTICAL FILE
DATABASE
MANAGEMENT SYSTEM
7 Write SQL queries for extracting data from more than one
table
CREATE Command:
The CREATE command is used to create new database in DBMS, and create new table in
database. In other word we can say CREATE command used to create new database
and table.
DESC Command:
The DESC is the short form of DESCRIBE command and used to display the
information about a table like column names and constraints on column name.
ALTER Command:
The SQL ALTER TABLE command is used to add, delete or modify columns in an existing
table. You should also use the ALTER TABLE command to add and drop various constraints
on an existing table.
DROP Command:
A SQL DROP TABLE statement is used to delete a table definition and all data from a table.
PRACTICAL -2
Aim: Write the queries for Data Manipulation Language (DML) in RDBMS.
INSERT Command:
SQL INSERT statement is a SQL query. It is used to insert a single or a multiple records in
a table.
SELECT Command:
The SELECT statement is the most commonly used command in Structured Query Language.
It is used to access the records from one or more database tables and views. It also
retrieves the selected data that follow the conditions we want.
UPDATE Command:
The UPDATE statement in SQL is used to update the data of an existing table in database.
We can update single columns as well as multiple columns using UPDATE statement as per
our requirement.
DELETE Command:
The DELETE Statement in SQL is used to delete existing records from a table. We can
delete a single record or multiple records depending on the condition we specify in the
WHERE clause.
PRACTICAL -3
Aim: Write SQL queries using Logical operations.
AND Operator:
This operator is used to temporarily show rows only when two or more than two
conditions are true.
OR Operator:
This operator is used to temporarily show rows when either any one of the given
conditions are true or all the conditions are true.
NOT Operator:
Not operator is used to temporarily show all the rows having all the conditions False.
IN Operator:
When this operator is used then it just shows all the rows having same values given in
bracket.
BETWEEN Operator:
It temporarily shows all the rows which lies between the two values given (including the
two values).
LIKE Operator:
Like operator is used to temporarily show all the rows having same alphanumeric in
given attribute. Examples are given in command prompt. Below.
PRACTICAL -4
Aim: Write SQL queries using Logical operations.
▪
AIRTHMETIC OPERATORS
1.SQL plus (+) operator: This operator is used to add two or more expressions or
numbers.
2. SQL minus (-) operator: This operator is used to subtract one expression or number
from another expression or number.
3. SQL multiply (*) operator: This operator is used to multiply two or more expressions
or numbers.
4. SQL divide (/) operator: This operator is used to divide one expressions or numbers
by another.
5. SQL modulo (%) operator: This operator returns the remainder (an integer) of
the division.
▪ COMPARISON OPERATORS
1.Equality Operator: This operator is used to test equality in the query.
2.Inequality Operator: In SQL, there are two ways to test for inequality in a query.
Either by using < > or! = operator.
3.Greater than Operator: We can use the > operator in SQL to test for an expression
greater than.
4.Greater than or equal Operator: In SQL, you can use the >= operator to test for
an expression greater than or equal to.
5. Less than Operator: We can use the < operator in SQL to test for an expression
less than.
6. Less than or equal to Operator: In SQL, you can use the <= operator to test for an
expression less than or equal to.
PRACTICAL -5
Aim: Write SQL query using character, number, date and group functions.
▪
AGGREGATE OPERATORS:
1.Average Operator: It returns average of the values in the selected columns. The
result can then be assigned to an alias using the AS clause.
2. MIN Operator: It returns the data from the row in which the specified
column contains the lowest value.
3. MAX Operator: It returns the data from the row in which the specified column
contains the highest value.
4. SUM Operator: The sum () function returns the total of all the values in a
specified column.
5. COUNT Operator: The MySQL count () function adds the number of rows that match
the filter criteria specified in a Select statement.
▪
CURRENT DATE AND TIME:
1.Now( ): This function returns the current date and time of the system.
4.Last_Day(): This function returns the corresponding value for the last day of
the month.
5.Date_format(): This function format the date value according to format string. The ‘%’
character is required before format specifier characters.
▪
CHARACTER OPERATORS:
1.ASCII: This function returns the ASCII code of the leftmost character of the string str.
3. CONCAT: This function returns the string that results from concatenating
the arguments.
4. INSTR: This function returns the location in a string of the specified substring.
▪
NUMBER FUNCTIONS:
1.POWER (X,Y): These function return the value of X raised to power of Y.
2. ROUND (M,N): This function returns M round to N places to right of a decimal point.
4. EXP (N): This function returns ‘e’ raised to Nth power where e = 2.71828183.
5. GREATEST: This function returns the greatest value in a list of expression.
7. MOD (N,M): This function returns the remainder of the first number divided by
the second number.
8.FLOOR: This function returns largest integer value that is equal to or less than a
number.
9.CEIL: This function returns the smallest integer value that is equal to or greater than
a number.
PRACTICAL -6
Aim: Write SQL queries for relational algebra.
SELECT: It is used to select the subset of the tuples of a relation that satisfies the
selection condition.
PROJECT: It selects only those columns or attributes in which the user is interested and
discards other.
▪ SET OPERATIONS
1.UNION OPERATOR: It is used to combine the results of two or more Select statements.
However, it will eliminate duplicate rows from its result set. In case of union, number of
columns and data type must be same in both the tables.
2.INTERSECTION OPERATOR: It is used to combine two SELECT statements, but it only
returns the records which are common from both SELECT statements. In case of
Intersect the number of columns and data type must be same.
3. DIFFERENCE OPERATOR: This operation combines result of two Select statements and
return only those result which belongs to first set of result.
PRACTICAL -7
Aim: Write SQL queries for extracting data from more than one table.
• JOINS
Database on which all the join operations are applied is as follows:
1. INNER JOIN: Inner join creates a new result table by combining column values of
two tables (A and B) based upon the join-predicate. It is similar to cross join or
Cartesian product.
2.OUTER JOIN:
>LEFT OUTER JOIN: The result of a left outer join for tables A and B always contains
all records of the "left" table (A), even if the join-condition does not find any
matching record in the "right" table (B).
> RIGHT OUTER JOIN:Every row from the "right" table (B) will appear in the joined
table at least once. If no matching row from the "left" table (A) exists, NULL will
appear in columns from A for those records that have no match in B.
> FULL OUTER JOIN: In the SQl the full outer join combines the result of both
left and right outer join and return all rows from the tables on both sides of the
join clause.
PRACTICAL -8
Aim: Write SQL queries to create, update and delete the VIEWs.
VIEW
A view is a virtual table. A view contains rows and columns, just like a real table. The fields
in a view are fields from one or more real tables in the database. You can add SQL functions,
WHERE and JOIN statements to a view and present the data as if the data were coming from
one single table.
DROPPING THE VIEW: We can delete a view in database using the drop view command.
UPDATING THE VIEW: If we want to add another column in the existing view.
PRACTICAL -9
Aim: Write SQL queries for sub queries and nested queries.
Subquery or Inner query or Nested query is a query within another SQL query and
embedded within the WHERE clause. A subquery is used to return data that will be used in
the main query as a condition to further restrict the data to be retrieved.
CASCADING OF QUERY:
Query within query is called cascading.
PRACTICAL -10