0% found this document useful (0 votes)
5 views

DBMS Lab File-BCA-507P-2

Uploaded by

bk401094
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)
5 views

DBMS Lab File-BCA-507P-2

Uploaded by

bk401094
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/ 3

LAB EXERCISE #1 - CREATING TABLES

1.1 Objective 1.2 Theory 1.3 Assignments

1.1 OBJECTIVE: Writing simple queries in SQL

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

CHAR(<size>): datatype is fixed-length alphanumeric string, which has a maximum length in


bytes. Its size can range from a minimum of 1 byte to a maximum of 2000 bytes. The default is 1.

VARCHAR2(<size>): datatype is a variable-length alphanumeric string, which has a maximum


length in bytes. VARCHAR2 columns require only the amount of space needed to store the data
and can store upto 4000 bytes. There is no default size for the varchar2 data type.

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

Elimination of duplicates from the select statement-


Syntax-
DBMS Lab (BCA-507(P))
SELECT DISTINCT columnname, columnname
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>;

For descending order:


SELECT <columnname1>,….,<columnname n>
FROM <tablename>
WHERE <searchcondition>
ORDER BY <columnname> DESC;

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

Following tables are created:


i) emp

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO


7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
DBMS Lab (BCA-507(P))

You might also like