Unit 3 SQL Extra-1-4
Unit 3 SQL Extra-1-4
Unit 3 SQL Extra-1-4
(4) Find the names of all customers who have a loan, an account, or both at the SBI branch.
{<c> I 31 «c, I> E borrower A 3 b, a «I, b, a> E loan A b = "SBI"»
V 3 a «c, a> E depositor A 3 b, n «a, b, n> E amount A b = "SBI"»)}
(5) Find the names of all customers who have an account at all the branches located in New
Delhi.
{<c> I 3 n «c, n> E customer) A V x,y,z «x,y,z> E branch A y = "New Delhi")
~ 3a,b «a,x,b> E account A <c,a> E depositor»)}
Q. Retrieve the name and address of all employees who work for the 'computer' department.
Ans. {qsv I (3 z) (3 I) (3 m) (EMPLOYEE (qrstuvwxyz) AND
DEPARTMENT (1m no) AND I = 'COMPUTER' AND (m = z»}
2.7 INTRODUCTION TO SQl
Structured Ouery Language (SOL) is a language that provides an interface to relational database
systems.
In common usage SOL also encompasses :
• DML (Data Manipulation Languages) for INSERTs, UPDATEs, DELETEs
• DDL (Data Definition Language) used for creating and modifying tables and other database
structures.
Features of SQL :
(1) SOL can be used by a range of users, including those with little or no programming
expenence.
(2) It is a non procedural language.
(3) It reduces the amount of time required for creating and maintaining systems.
(4) It is an English-Like Language.
Components of SQL : There are following components of SOL.
(1) DDL
It is a set of SOL commands used to create, modify and delete data base structure but not data.
For examples "
(i) CREATE: To create objects in the database.
(ii) ALTER: Alters the structure of the database.
(iii) DROP: Delete objects from the database.
(iv) TRUNCATE : Remov~ all records from a table, including all spaces allocated for the records
are removed.
(v) COMMENT: Add comments to the data dictionary.
(2) DML (Data Manipulation Language)
It is the area of SOL that allows changing data within the database.
For Examples "
(i) INSERT : Insert data into a table.
(ii) UPDATE: Updates existing data within a table.
(iii) DELETE : Deletes all records from a table, the space for the records remain.
(iv) LOCK TABLE: Control concurrency.
(3) DCL (Data Control Language)
It is the components of SOL statements that control access to data and to the database.
RELATIONAL DATA MODEL CONCEPTS 67
For Examples :
(i) COMMIT: Save work done
(ii) SAVE POINT: Identify a point in a transaction to which you can later roll back.
(iii) ROLL BACK: Restore database to original since the last COMMIT.
(iv) GRANT/REVOKE: Grant or take back permissions to or from the oracle users.
(v) SET TRANSACTION: Change transaction options like what rollback segment to use.
(4) DQL (Data Query Language)
It is the component of SQL statement that allows getting data from the database and imposing
ordering upon it.
For example:
(1) SELECT: Retrieve data from the database.
2.7.1 Data Types
• Data types comes in several forms and sizes, allowing the programmer to create tables suited
to the scope of the project.
• CHAR (Size) : This data type is used to store character strings values of fixed length. The
maximum number of characters this data type can hold is 255 characters.
e.g., In case of 'Name Char (15)" then data held in the variable Name is only 15 characters in
length.
• VARCHAR (Size)NARCHAR2 (size) : This data type is used to store variable length
alphanumeric data. The maximum type this can hold is 2000 characters.
• NUMBER (P, S) : The NUMBER data type is used to store numbers. The precision (P),
determines the maximum length of the data, whereas the scale, (S), dertermines the number
of places to the right of the decimal. The maximum precision (P), is 38 digits.
• DATE: This data type is used to represent date and time. The standard format is DD-MM-YY
as in 26-June-07.
The Date time stores date in the 24-hour format. By default, the time in a date field is
12 : 00 : 00 AM, if no time portion is specified.
• LONG: The LONG data type is used to store variable length character strings containing
upto 2 GB.
LONG data can be used to store arrays of binary data in ASCII format.
• RAW/LONG RAW: The RAW/LONG RAW data types is used to store binary data, such as
digitized picture or image.
RAW data type can have a maximum length of 255 bytes.
LONG RAW data type can contain up to 2 GB.
• ROWID (rowid) : The format of the rowid is :
BBBBBBB . RRRR . FFFFF
where BBBBBBB is the block in the database fIle;
RRRR is the row in the block;
FFFFF is the data base fIle.
• Boolean: Valid in PL/SQL but this data type does not exist in oracle 8 i or oracle 9 i.
2.7.2 Types of SOL Commands
(1) The Create table Command:
Syntax: CREATE TABLE table name
68 DATABASE MANAGEMENT SYSTEMS