Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Project
Report
CONTENTS
• Introduction
• Codd’s Rule
• Structure Query Language
• Types of SQL commands
• Views
• Indexes
• Type of Index
• Using Index
• SQL Commands
• Bibliography
INTRODUCTION
The foundation of Relational Database technology was laid by Dr. E.F. Codd, who in
his papers ‘A Relational Model of Data for Large Shared Data Banks’ laid the basic
principle of the RDBMS. He laid down certain principle of database management,
referred to as relational model. The principles were soon applied to as experimental
systems, and start was made on the design of a database language that would
interact with such system.
The relational model was evolved through many stages since its inception in the
early 1970s. Performance of the model was an early concern. However, performance
can be measured in the two ways – performance at execution time and performance
during design and implementation. In the first case we measure the performance
when the database is under construction. In the second case the relational model
was a clear winner from the start outperforming both hierarchical and network
models by considerable margins. Although its critics attacked the slow processing
speeds of the earlier relational implementation, the relational model no longer
suffers from these shortcomings.
The access language SQL, together with its earlier predecessors and competitors,
also received a lot of criticism. Early version of SQL was not uniform and
standardized in the treatment of certain concepts. But with the introduction of ANSI
SQL standards, this problem- the lack of standardization – also got resolved.
CODD’S RULE
Dr. E.F.Codd was the founder of RDBMS and he laid down certain principle of
database management – system referred to as RDBMS. He provides a set of
following 12 rules which qualify a database product as relational:-
6. View Updating Rule:- Any view that can be updated theoretically can be
updated using the RDBMS. Data consistency is ensured since the changes
made in the view are transmitted to base table and vice versa.
7. High Level Insert, Update and Delete:- The RDBMS supports insertion,
updating and deletion at a table level. The performance is improved since the
commands act on a set of records rather than one record at a time.
12. Non subversion Rule:- If the RDBMS has a language that access the
information of a record at a time, this language should not be used to bypass
the integrity constraints. This is necessary for data integrity.
The basic features of all these different flavors are the same – they have the same
base, the ANSI SQL standard. Implementation of the advanced features of SQL
differs from vendor to vendor, but here also the concepts are the same. So the SQL
skills are very much transferable. In other words, except for the vendor specific
enhancements, the SQL is the same.
Although SQL is the default language used in an RDBMS, MS-SQL Server has added
more features to the base level syntax of SQL and has its own SQL called Transact-
SQL (T-SQL).
TYPES OF SQL COMMANDS
SQL can be classified based on its functionality. SQL provides a comprehensive set
of commands for a variety of tasks including the following:
⇒ Querying Data
Data Definition Language is used to create, alter and delete database objects.
The commands used are CREATE, ALTER and DROP. The principal logical
data definition statements are CREATE TABLE, CREATE VIEW, CREATE
INDEX, ALTER TABLE, DROP TABLE, DROP VIEW and DROP INDEX.
Data Manipulation Language commands let users insert, modify and delete
the data in the database. SQL provides three data manipulation statement –
INSERT, UPDATE and DELETE.
This is one of the most commonly used SQL statements. This SQL statement
enables the users to query one or more tables to get the information they
want. SQL has only one data query statement – SELECT.
4. Data Control Language (DCL)
The data control language consists of commands that control the user’s
access to the database objects. Thus DCL is mainly related to the security
issues that are determining who has access to the database objects and what
operations they can perform on them. The task of the DCL is to prevent
unauthorized access to data. The Database Administrator (DBA) has the
power to give and take the privilege to a specific user, thus giving or denying
access to the data. The DCL commands are GRANT and REVOKE.
Data administration commands allow the user to perform audits and analysis
on operations within the database. They are also used to analyze the
performance of the system. Two data administration command are START
AUDIT and STOP AUDIT. One thing to be remembered here is that, data
administration is totally different from database administration. Database
administration is the overall administration of the database and data
administration is only a subset of that.
VIEWS
A view is a virtual table, which gives access to a subset of columns from one or
more tables. It is a query stored as an object in the database. Therefore, a view is an
object that derives its data from one or more tables. These tables are referred to as
the base or underlying tables.
A view serves as a security mechanism. It ensures that users are able to retrieve
and modify only the data which is seen by them. The remaining data in the
underlying tables can neither be seen nor accessed. The usage of complex queries
can also be simplified using views. Complex queries can be stored in the form of a
view and data from the view can be extracted using simple queries.
After the view is defined it can be referenced like any other table in the database.
Although a view is similar to a table, it is not stored in the database. It derives its set
of values from the underlying tables.
AS sub query
vwPublisherTitles
To get the output, like in the above table, you have to enter the following command:
AS
The output can be seen using views by entering the following simple SELECT
statement: SELECT * FROM vwPublisherTitles
Advantages of Views
INDEXES
An index is a structure that provides faster access to the rows of a table based on
the values of one or more columns. The index stores data values and pointers to the
rows where those data values occur. In the index the data values are stored and
stored in the ascending or descending order. So, the RDBMS can quickly search the
index to find a particular data values and hence the row associated with it.
GUIDELINES FOR INDEX CREATION ARE:-
⇒ Columns that are regularly used in joins should be indexed, because the
RDBMS can perform the join faster.
⇒ Indexing on columns that have one or two values like gender will not have
any real performance improvement.
⇒ Indexing small tables with only a few rows does not improve the
performance.
TYPE OF INDEXES
• COMPOSITE INDEX
When an index is made up of more that one column it is called composite index.
Composite index columns do not have to be specified in the same order as in the
CREATE TABLE statement. You can use any order you want for better performance,
it is a good idea to start with the column that you use most often in searches.
• UNIQUE INDEX: -
A unique index is one in which no two rows are permitted or in which no duplicate
values are allowed for the same index value. These indexes are usually created on
the primary key of a table. You specify the index as a unique index by using the
keyword UNIQUE. For unique indexes, the RDBMS checks for duplicate values
when the index is created and each time new data is added.
• CLUSTERED INDEX: -
Many RDBMS offer you the choice of making your index clustered or non-clustered.
When you create a clustered index, it means that the system will sort the rows of a
table when there is a change made to the index. In non-clustered index, the physical
order of the rows is not the same as their indexed order. There can be as many non-
clustered indexes per table. Clustered indexes are much faster than non-clustered
ones.
USING INDEXES
A unique index on the primary key prevents duplicate and gurantees that every
value in primary key column will infact uniquely identifies the row.
A column that is often accessed in a sorted order should be indexed so that the
system can take advantage of indexed order.
SQL COMMANDS
CREATING TABLE: -
Example 1:- The detail about a newspaper that publishes advertisement for
Tebisco, Inc to be stored in a Recruitment database
Attributes Data
Region Delhi
State Delhi
Zip 110001
Phone (011)2343242
Solution:-
CREATE Statement : -
vRegion varchar(20),
vTypeofNewspaper varchar(20),
vContactPerson varchar(35),
vHOAddress varchar(35),
cCity char(20),
cState char(20),
cZip char(10),
cCountryCode char(3),
cPhone char(15)
2.INSERT Statement :-
Insert statement is used to insert the values in a table. To insert values in above
table, command should be:
3. DROP Statement: -
The above command will delete the Newspaper table from the database.
Example 2:-
Let us take table named Record
Table: Record
4. SELECT Statement
SELECT statement can be used to access and retrieve data from the database.
Syntax:
FROM table_name
QUERY
⇒ SELECT VFirstName, cCity
FROM Record
The above statement will retrieve VFirstName and cCity from Record
OUTPUT
vFirstName cCity
Rahul Delhi
Sanjay Punjab
5. WHERE Statement
WHERE Statement is used with SELECT statement to display the Selected files
from a table.
Syntax:
WHERE search_condition
QUERY
FROM Record
The above query will show the vFirstName and vLastName of record where cCity is
Delhi
OUTPUT
vFirstName vLastName
Rahul Sharma
EXAMPLE 3:-
6.Distinct :
FROM BOOK;
The result will be the name of the publishers, with no duplicate as shown below:
Publisher
Bantam Books
Century Books
Corgi Books
Dell Books
Harper Collins
Headline Books
Macmillan
Mandarin Books
Pan Books
Random House
Signet Books
Warner Books
FROM Book
OUTPUT
BETWEEN can be used to get those items that fall within a range
FROM Book
OUTPUT
Title Author Publisher Price
Like is very popular clause and also very useful. E.g. if you want to get all the
details of the books whose publisher’s name starts with ‘S’, use LIKE as follows:
FROM Book
OUTPUT
For getting the result in a particular order we use thr ORDER BY clause. Consider
the query ‘Get all the distributor details in descending order of discount’. The SQL
statement will be as follows:
QUERY
WHERE Price>300
OUTPUT
QUERY
OUTPUT
⇒ SELECT COUNT(Name)
FROM Employee
OUTPUT:- 4
QUERY 2:-Get the number of employees in the department D1 and basic pay less
than 6000
⇒ SELECT COUNT(Name)
FROM Employee
OUTPUT:- 2
2. SUM()
QUERY 1:-Find the total basic pay for all the employees in the organization.
⇒ SELECT SUM(Basic)
FROM Employee;
OUTPUT:- 71800
QUERY 2:- Find the total Basic Pay for all the employees in the department ‘D1’
⇒ SELECT SUM(Basic)
FROM Employee
WHERE Deptid=’D1’
OUTPUT:- 25800
3.AVG()
⇒ SELECT AVG(HRA)
FROM Employee
OUTPUT:- 1196.67
QUERY 2:-Find the average pay of an employee in the department ‘D1’ whose HRA
is greater than 1000.
FROM Employee
OUTPUT:- 5408.33
4. MAX() and MIN()
QUERY 1:-Find the name of the Employee who gets the maximum basic pay.
⇒ SELECT Name
FROM Employee
OUTPUT:-
Name
Joseph
BIBLIOGRAPHY
By Rajesh Narang