0% found this document useful (0 votes)
21 views9 pages

Assignment 5

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views9 pages

Assignment 5

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

S.E.Q.U.

L (STRUCTURED ENGLISH QUERY LANGUAGE)

 SQL stands for Structured Query Language.


 It is the most commonly used relational database language today.
 SQL works with a variety of different fourth-generation (4GL)
programming languages, such as Visual Basic.

 INTRODUCTION TO SQL –

SQL consists of a set of commands for defining, accessing, and


managing relational databases.
In 1970, E.F. Codd at IBM Research Labs in San Jose, California
published “A Relational Model of Data for Large Shared Data Banks”
(Communications of the ACM, Vol. 13, No. 6, June 1970) in which he
described a set of abstract principles for database management - the
relational model. The field of relational database technology has its
origins in that paper. This research described several relational
languages which implement some/all of the features of the abstract
relational model. One of these languages which was created in 1974-
75 was the “Structured English Query Language” (SEQUEL), defined by
Donald Chamberlin and others at IBM Labs. The first IBM prototype
was called SEQUEL-XRM (1974-75).
A revised version of SEQUEL-XRM was defined in 1976-77 and named
SEQUEL/Z. The name was changed to SQL for legal reasons. A
prototype of this became operational in 1977 called System R. Due to
the success of System R, vendors rushed to create their own SQL
products. The Oracle database was released before IBM's own product.
In 1982, the American National Standards Institute (ANSI) chartered its
Database Committee (X3H2) to develop a standard for a relational
language. In 1986, the X3H2 proposal was ratified by ANSI which
consisted essentially of the IBM dialect of SQL. In 1987, the ANSI
standard was accepted as an international standard by the
International Organization for Standards (ISO).
The original standard is also known as SQL/86.Enhancements were
made over time SQL/89 - included an Integrity Enhancement Feature
SQL/92 - ISO and ANSI developed a revised standard also known as
SQL2 SQL/99 - “SQL3” incorporates object-oriented access A
consortium of vendors known as the SQL Access Group has been
working to enhance interoperability across different systems.

 What Is SQL?
 When a user wants to get some information from a database file, he
can issue a query.
 A query is a user–request to retrieve data or information with a
certain condition.
 SQL is a query language that allows user to specify the conditions.
(instead of algorithms)
 Concept Of SQL -
 The user specifies a certain condition.
 The program will go through all the records in the database file and
select those records that satisfy the condition.(searching).
 Statistical information of the data.
 The result of the query will then be stored in form of a table.
 Data Types Of SQL :
 Data Manipulation
 Data Definition
 Data Administration
 All are expressed as an SQL statement or command.
 Notations To Define SQL Statements:
 UPPER-CASE letters represents reserved words.
 Lower-case letters represents user-defined words.
 | indicates a choice among alternatives; (e.g. a | b | c).
 { } indicates a required element.
 [ ] indicates an optional element.
 … indicates optional repetition of an item zero or more times.
 Underlined words represent default values.

 SQL Requirements:
 SQL Must be embedded in a programming language, or used with a
4GL like VB
 SQL is a free form language so there is no limit to the the number of
words per line or fixed line break.
 Syntax statements, words or phrases are always in lower case;
keywords are in uppercase.

 SQL Is A Relational Database:


A Fully Relational Database Management System must:
 Represent all info in database as tables
 Keep logical representation of data independent from its physical
storage characteristics
 Use one high-level language for structuring, querying, and changing
info in the database
 Support the main relational operations
 Support alternate ways of looking at data in tables
 Provide a method for differentiating between unknown values and
nulls (zero or blank)
 Support Mechanisms for integrity, authorization, transactions, and
recovery.
 DESIGN:
 SQL represents all information in the form of tables
 Supports three relational operations: selection, projection, and join.
These are for specifying exactly what data you want to display or
use
 SQL is used for data manipulation, definition and administration.
TABLES
 Tables can be thought of as files, with rows representing records
and the columns as fields.
 The SQL standard always uses the terms table, row and column.
 SQL statements can be invoked either interactively or from within
an application.
 Interactive SQL generally displays the results on the screen.
 Invocation from a program means the results are made
available as input to the program.

Columns Rows
describe descr
one ibe
characterist the
ic of the Occu
entity
Types of Tables rrenc
e of
There are two types of tables which make up a relational database in
SQL.
an management
 User Tables: contain information that is the database
system
Entity
 System Tables: contain the database description, kept up to date by
DBMS itself
Relation Table

Tuple Row

Attribute Colum
n

Creating Tables
 Empty tables are constructed using the CREATE TABLE statement.
 Data must be entered later using INSERT.
CREATE TABLE S ( SNO CHAR(5),
SNAME CHAR(20),
STATUS DECIMAL(3),
CITY CHAR(15),
PRIMARY KEY (SNO)
 A table name and unique column names must be specified.
 Columns which are defined as primary keys will never have two
rows with the same key value.
 Primary key may consist of more than one column (values unique in
combination) called composite key.

CREATE TABLE SP ( SNO CHAR(5),


PNO CHAR(5),
QTY DECIMAL(5),
PRIMARY KEY (SNO,PNO),
FOREIGN KEY (SNO) REFERENCES S,
FOREIGN KEY (PNO) REFERENCES P )

 Foreign keys refer to other tables.


– Any key in SP.SNO must also appear in S.SNO and any key in
SP.PNO must appear in P.PNO - a shipment cannot exist unless
the supplier and part also exist.

A Suppliers-and-Part Database Example-


 Tables
– S : suppliers
– P : parts (and where to ship an order)
– SP : shipment of parts by suppliers
Table S
SNO SNAME STATUS CITY

S1 SMITH 20 LONDON
S2 JONES 10 PARIS
S3 BLAKE 30 PARIS
S4 CLARK 20 LONDON

Primary Key = SNO

Table P

PNO PNAME COLOUR WEIGHT CITY

P1 NUT RED 12 LONDON

P2 BOLT GREEN 17 PARIS

P3 SCREW BLUE 17 ROME

P4 SCREW RED 14 LONDON

Primary Key = PNO


Table SP
SNO PNO QTY

S1 P1 300

S1 P2 200

S2 P1 300

S3 P2 200

S4 P4 400

Primary Key = SNO and PNO


Data Retrieval (Queries)
 Queries search the database, fetch info, and display it. This is done
using the keyword SELECT
 SELECT * FROM publishers
 SELECT is used for data retrieval.
 FROM indicates the table from which to retrieve the data.
 WHERE is used to describe column features that are desired in the
retrieved data.
pub_id pub_name address state

0010 Pragmatics 4 4th Ln IL 

0736 New Age Books 1 1st Street MA 

0987 Binnet & Hardley 2 2nd Street DC

1120 Algodata Infosys 3 3rd Street CA 

No WHERE statement will cause all rows to be returned.
 You can use all of the standard comparisons (<,<=,>,>=,=).
 Literal strings must appear in single quotes.

pub_id pub_name address state

0736 New Age Books 1 1st Street MA

0987 Binnet & Hardley 2 2nd Street DC

1120 Algodata Infosys 3 3rd Street CA

 The * Operator asks for every column in the table.


 Queries can be more specific with a few more lines
 SELECT *
frompublishers
where state = ‘CA’

1120 Algodata Infosys 3 3rd Street CA

 Only publishers in CA are displayed


Data Input
 Putting data into a table is accomplished using the keyword
INSERT.
VARIABLE
INSERT INTO publishers
KEYWORD
VALUES (‘0010’, ‘pragmatics’, ‘4 4th Ln’, ‘chicago’, ‘il’)
 Table is updated with new information
To insert data in the current table, use the keyword INSERT INTO
INSERT INTO authors values(‘000000001’, ‘John Smith’).
 Then issue the statement
 SELECT * FROM authors
If you only want to display the author’s name and city from the following
table:

auth_id auth_name auth_city auth_state

123456789 Jane Doe Dearborn MI

000000001 John Smith Taylor MI

SELECT auth_name, auth_city FROM publishers

auth_name auth_city

Jane Doe Dearborn

John Smith Taylor

 Using SQL:
 SQL statements can be embedded into a program (cgi or perl script,
Visual Basic, MS Access)

OR
 SQL statements can be entered directly at the command prompt of
the SQL software being used (such as mySQL)
To begin, you must first CREATE a database using the following SQL
statement:
CREATE DATABASE data base_name
Depending on the version of SQL being used the following statement is
needed to begin using the database:
USE database_name
 Using SQL:
To delete data from a table, use the DELETE statement:
DELETE from authors WHERE auth_name=‘John Smith’
auth_id auth_name auth_city auth_state

123456789 Jane Doe Dearborn MI

000000001 John Smith Taylor MI

 Using SQL:
 To change a table in a database use ALTER TABLE. ADD adds a

Typ Initiali
characteristic.
e
 ALTER TABLE authors ADD birth_date datetime null. zer
auth_id auth_name auth_city auth_state

123456789 Jane Doe Dearborn MI

000000001 John Smith Taylor MI

ADD puts a new column in the table called birth_date


 Using SQL:
 To delete a column or row, use the keyword DROP
 ALTER TABLE authors DROP birth_date

auth_id auth_name auth_city auth_state

123456789 Jane Doe Dearborn MI

000000001 John Smith Taylor MI

DROP removed the birth_date characteristic from the table

 Using SQL:
The DROP statement is also used to delete an entire database.
DROP DATABASE authors

DROP removed the database and returned the memory to system

 Advantages of SQL :
1. View the data without storing the data into the object.
2. Restrict the view of a table i.e. can hide some of columns in the
tables.
3. Join two or more tables and show it as one object to user.
4. Restrict the access of a table so that nobody can insert the rows
into the table.
5. Data independence , Currency, Improved security , Reduced
complexity , Convenience ,Customization , Data integrity.
 Disadvantages of SQL :
1. Can not use DML operations on this.
2. When table is dropped view becomes inactive.. it depends on the
table objects.
3. It is an object, so it occupies space
4. Update restriction, Structure restriction , Performance
Conclusion:
 SQL is a versatile language that can integrate with numerous 4GL
languages and applications
 SQL simplifies data manipulation by reducing the amount of code
required.
 More reliable than creating a database using files with linked-list
implementation.

You might also like