DBMS Lab File-BCA-507P-2
DBMS Lab File-BCA-507P-2
1.2 THEORY & CONCEPTS: SQL (Structured Query Language) is a nonprocedural language,
you specify what you want, not how to get it. A block structured format of English key words is
used in this query language. It has the following components.
DDL (Data Definition Language): The SQL DDL provides command for defining relation
schemas, deleting relations and modifying relation schema.
DML (DATA Manipulation Language): It includes commands to insert tuples into, delete tuples
from and modify tuples in the database.
View definition: The SQL DDL includes commands for defining views. Transaction Control- SQL
includes for specifying the beginning and ending of transactions.
Embedded SQL and Dynamic SQL: Embedded and Dynamic SQL define how SQL statements
can be embedded with in general purpose programming languages, such as C, C++, JAVA,
COBOL, Pascal and Fortran.
Integrity: The SQL DDL includes commands for specifying integrity constraints that the data
stored in the database must specify. Updates that violate integrity constraints are allowed.
Authorization: The SQL DDL includes commands for specifying access rights to relations and
views.
Domain types in SQL: The SQL standard supports a variety of built in domain types, including:
Char (n)- A fixed length character length string with user specified length .
Varchar (n)- A variable character length string with user specified maximum length n.
Int- An integer.
Small integer- A small integer.
Numeric (p, d)-A Fixed point number with user defined precision.
Real, double precision- Floating point and double precision floating point numbers with
machine dependent precision.
Float (n)- A floating point number, with precision of at least n digits.
Date- A calendar date containing a (four digit) year, month and day of the month.
Time- The time of day, in hours, minutes and seconds e.g. Time ’09:30:00’.
Number- Number is used to store numbers (fixed or floating point).
NUMBER(<p>, <s>): datatype stores numbers with a precision of p digits and a scale of s digits.
The precision and scale values are optional. The precision can be between 1 and 38, and the scale
DBMS Lab (BCA-507(P))
has range between -82 and 127.
DATE: datatype is used to store date and time information, the DATE datatype occupies a storage
space between seven bytes. The following information is contained within each DATE datatype:
Century
Year
Month
Day
Hour
Minute
Second
The default format is DD-MON-YY. The SYSDATE function returns the current system date and
time from the database server to which you’re currently connected.
Operators:
Arithmetic Operators: +, -, *, /
Concatenation Operators: ||
Set Operators:
UNION: returns all rows from either queries; no duplicate rows
UNION ALL: returns all rows from either queries; including duplicates
INTERSECT: returns distinct rows that are returned by both queries
MINUS: returns distinct rows that are returned by the first query but not returned by the
second
Comparison Operators:
= (Equality)
!=, <>, or ^= (Inequality)
< (Less Than)
> (More Than)
<= (Less Than or Equal To)
>= (Greater Than or Equal To)
ANY or SOME: operators are used to compare a value to each value in a list or subquery. These
operators must be preceeded by the comparison operators.
ALL: operator is used to compare a value to every value in a list or subquery. These operators must
be preceeded by the comparison operators.
Logical Operators: NOT, AND, OR
Writing Simple Queries: A query is a request for information from the database tables. Simple
queries are those that retrieve data from a single table. The basis of a query is the SELECT
statement.
Using the SELECT statement:
Syntax:
SELECT <columnname1>,…., <columnname n>
FROM <tablename>;
Column Alias Names: Column alias name is defined next to the column name with a space or by
Sing the keyord AS.
Syntax:
SELECT <columnname1> AS <aliasname1>, ….,<columnname n> AS <aliasname n>
FROM <tablename>;
Limiting Rows: A WHERE clause is used in SELECT statement to limit number of rows
processed.
Syntax-
SELECT <columnname1>,….,<columnname n>
FROM <tablename>
WHERE <searchcondition>;
Sorting Rows: ORDER BY clause is used to sort the rows in the resultset in ascending or
descending order. The default order is ascending.
Syntax:
For ascending order:
SELECT <columnname1>,….,<columnname n>
FROM <tablename>
WHERE <searchcondition>
ORDER BY <columnname>;
Other Operators:
IN and NOT IN: the IN and NOT In operators are used to test a membership condition. IN
evaluates to true if the value exists in the list or the resultset from the subquery. The NOT
IN evaluates to true if the value does not exist in the list or the resultset from a subquery.
BETWEEN: operator is used to test a range. BETWEEN A AND B evaluates to true if the
value is greater than or equal to A and less than or equal to B.
LIKE: operator is used to perform pattern matching. The pattern search character % is used
to match any character and any number of characters. _ is used to match any single
character. To search for the actual character % in the pattern search, you should include an
escape character (/) in the search string and notify using ESCAPE clause.
1.3 ASSIGNMENTS
Assignment 1