Someshwar M. Moholkar
WCBT, Solapur
(Dept.of Bioinformatics)
What is SQL
 Structured Query Language
 Communicate with databases
 Used to created and edit databases
 Also used to create queries ,forms and reports
History of SQL
 SQL: Structured Query Language
 SQL is based on the relational tuple calculus
 SEQUEL: Structured English Query Language; part of
SYSTEM R, 1974
 SQL/86: ANSI & ISO standard
 SQL/89: ANSI & ISO standard
 SQL/92 or SQL2: ANSI & ISO standard
 SQL3: in the works...
 SQL2 supported by ORACLE, SYBASE, INFORMIX,
IBM DB2, SQL SERVER, OPENINGRES,...
SQL
SQL consists of the following parts:
 Data Definition Language (DDL)
 Interactive Data Manipulation Language (Interactive
DML)
 Embedded Data Manipulation Language (Embedded
DML)
 Views
 Integrity
SQL Commands
The standard SQL COMMANDS are CREATE ,SELECT,
INSERT,UPDATE,DELETE and DROP.
DDL
Command Description
CREATE creates a new table or other object in database
ALTER Modifying an existing database object
DROP Deletes an entire table
DML (Data Manipulation Language)
Command Description
INSERT Creates a record
UPDATE Modifies records
DELETE Deletes records
DCL(Data Control Language)
Commands Description
GRANT Gives a privilege to user
REVOKE Takes back privilege granted from user
SQL
 Data Definition Language (DDL)
 Create/alter/delete tables and their attributes
 Following lectures...
 Data Manipulation Language (DML)
 Query one or more tables – discussed next !
 Insert/delete/modify tuples in tables
PRIMARY Key:
A Primary key is a field in a table uniquely
Identifies each row/record in a database table. Primary
Keys must contains unique values.
A table can have only
one primary key, which may consist of single or multiple
fields. When multiple fields are used as a primary key,
they are called a ‘composite key’.
sql>create table customers
2(
id int(12)
3 name varchar (20) ,
4 age int(2),
5 address char (25) ,
6 salary decimal (18, 2),
7 primary key (id, name)
);
FOREIGN Key:
A foreign key is a key used to link two
tables together. This is sometimes called a
referencing key.
Foreign Key is a column or
a combination of columns whose values
match a Primary Key in a different table.
Data
Integrity
Data Integrity
Data Integrity:
 Entity Integrity : There are no duplicate rows in a
table.
Domain Integrity : Enforces valid entries for a
given column by restricting the type, the format,
or the range of values.
Referential Integrity : Rows cannot be deleted
which are used by other records.
User-Defined Integrity : Enforces some specific
business rules that do not fall into entity, domain,
or referential integrity.
Database Normalization
Database Normalization
Database Normalization
Database normalization is the process of
efficiently organizing data in a database. There are
two reasons of the normalization process:
 Eliminating redundant data, for example, storing
the same data in more than one table.
 Ensuring data dependencies make sense.
Types of Normalization
 First Normal Form (1NF)
 Second Normal Form (2NF)
 Third Normal Form (3NF)
First Normal Form:
 Define the data items required, because
they become the columns in a table. Place
related data items in a table.
 Ensure that there are no repeating groups
of data.
 Ensure that there is a primary key.
Second Normal Form:
Second normal form states that it should meet
all the rules for 1NF and there must be no partial
dependences of any of the columns on the primary key.
Third Normal Form:
A table is in third normal form when the following
conditions are met:
 It is in second normal form.
 All nonprimary fields are dependent on the primary key.
SQL Data types
 String types
 CHAR(n) – fixed-length character data, n characters long
Maximum length = 2000 bytes
 VARCHAR2(n) – variable length character data, maximum
4000 bytes
 LONG – variable-length character data, up to 4GB. Maximum
1 per table
 Numeric types
 NUMBER(p,q) – general purpose numeric data type
 INTEGER(p) – signed integer, p digits wide
 FLOAT(p) – floating point in scientific notation with p binary
digits precision
 Date/time type
 DATE – fixed-length date/time in dd-mm-yy form
Available statements
SQL (1/2)
Giacomo.Govi@cern.ch 20
Statement Description
SELECT Data retrieval
INSERT
UPDATE
DELETE
Data Manipulation Language (DML)
CREATE
ALTER
DROP
RENAME
TRUNCATE
Data Definition Language (DDL)
COMMIT
ROLLBACK
SAVEPOINT
Transaction Control
GRANT
REVOKE
Data Control Language (DCL)
Rows
Tables/Objects
Manages
DML
SQL & Tools
 SQL statements can be submitted via:
 DB API’s for programming languages (C, C++, Java,
Python, PHP, …)
 GUI applications (Excel, Access)
 stored procedures (PL/SQL, Java)
 Oracle tools (Reports, Forms, Designer…)
 SQL*Plus (Oracle!) is the basic tool to submit
SQL commands (available on all CERN
platforms).
Summary
What is SQL
History of SQL
SQL Commands
PRIMARY Key
Data Integrity
Database Normalization
SQL Data types
References
Go to http://sqlcourse.com/drop.html
http://sqlcourse.com/insert.html
 http://www.benthicsoftware.com/
 Sprouse, W. and Anderson, A. B. Land Condition Trend
Analysis (LCTA)
 Simply Easy Learning by tutorialspoint.com
 Basic SQL and History

Basic SQL and History

  • 1.
    Someshwar M. Moholkar WCBT,Solapur (Dept.of Bioinformatics)
  • 2.
    What is SQL Structured Query Language  Communicate with databases  Used to created and edit databases  Also used to create queries ,forms and reports
  • 3.
    History of SQL SQL: Structured Query Language  SQL is based on the relational tuple calculus  SEQUEL: Structured English Query Language; part of SYSTEM R, 1974  SQL/86: ANSI & ISO standard  SQL/89: ANSI & ISO standard  SQL/92 or SQL2: ANSI & ISO standard  SQL3: in the works...  SQL2 supported by ORACLE, SYBASE, INFORMIX, IBM DB2, SQL SERVER, OPENINGRES,...
  • 4.
    SQL SQL consists ofthe following parts:  Data Definition Language (DDL)  Interactive Data Manipulation Language (Interactive DML)  Embedded Data Manipulation Language (Embedded DML)  Views  Integrity
  • 5.
    SQL Commands The standardSQL COMMANDS are CREATE ,SELECT, INSERT,UPDATE,DELETE and DROP. DDL Command Description CREATE creates a new table or other object in database ALTER Modifying an existing database object DROP Deletes an entire table
  • 6.
    DML (Data ManipulationLanguage) Command Description INSERT Creates a record UPDATE Modifies records DELETE Deletes records
  • 7.
    DCL(Data Control Language) CommandsDescription GRANT Gives a privilege to user REVOKE Takes back privilege granted from user
  • 8.
    SQL  Data DefinitionLanguage (DDL)  Create/alter/delete tables and their attributes  Following lectures...  Data Manipulation Language (DML)  Query one or more tables – discussed next !  Insert/delete/modify tuples in tables
  • 9.
    PRIMARY Key: A Primarykey is a field in a table uniquely Identifies each row/record in a database table. Primary Keys must contains unique values. A table can have only one primary key, which may consist of single or multiple fields. When multiple fields are used as a primary key, they are called a ‘composite key’.
  • 10.
    sql>create table customers 2( idint(12) 3 name varchar (20) , 4 age int(2), 5 address char (25) , 6 salary decimal (18, 2), 7 primary key (id, name) );
  • 11.
    FOREIGN Key: A foreignkey is a key used to link two tables together. This is sometimes called a referencing key. Foreign Key is a column or a combination of columns whose values match a Primary Key in a different table.
  • 12.
  • 13.
    Data Integrity:  EntityIntegrity : There are no duplicate rows in a table. Domain Integrity : Enforces valid entries for a given column by restricting the type, the format, or the range of values. Referential Integrity : Rows cannot be deleted which are used by other records. User-Defined Integrity : Enforces some specific business rules that do not fall into entity, domain, or referential integrity.
  • 14.
  • 15.
    Database Normalization Database normalizationis the process of efficiently organizing data in a database. There are two reasons of the normalization process:  Eliminating redundant data, for example, storing the same data in more than one table.  Ensuring data dependencies make sense.
  • 16.
    Types of Normalization First Normal Form (1NF)  Second Normal Form (2NF)  Third Normal Form (3NF)
  • 17.
    First Normal Form: Define the data items required, because they become the columns in a table. Place related data items in a table.  Ensure that there are no repeating groups of data.  Ensure that there is a primary key.
  • 18.
    Second Normal Form: Secondnormal form states that it should meet all the rules for 1NF and there must be no partial dependences of any of the columns on the primary key. Third Normal Form: A table is in third normal form when the following conditions are met:  It is in second normal form.  All nonprimary fields are dependent on the primary key.
  • 19.
    SQL Data types String types  CHAR(n) – fixed-length character data, n characters long Maximum length = 2000 bytes  VARCHAR2(n) – variable length character data, maximum 4000 bytes  LONG – variable-length character data, up to 4GB. Maximum 1 per table  Numeric types  NUMBER(p,q) – general purpose numeric data type  INTEGER(p) – signed integer, p digits wide  FLOAT(p) – floating point in scientific notation with p binary digits precision  Date/time type  DATE – fixed-length date/time in dd-mm-yy form
  • 20.
    Available statements SQL (1/2) Giacomo.Govi@cern.ch20 Statement Description SELECT Data retrieval INSERT UPDATE DELETE Data Manipulation Language (DML) CREATE ALTER DROP RENAME TRUNCATE Data Definition Language (DDL) COMMIT ROLLBACK SAVEPOINT Transaction Control GRANT REVOKE Data Control Language (DCL) Rows Tables/Objects Manages DML
  • 21.
    SQL & Tools SQL statements can be submitted via:  DB API’s for programming languages (C, C++, Java, Python, PHP, …)  GUI applications (Excel, Access)  stored procedures (PL/SQL, Java)  Oracle tools (Reports, Forms, Designer…)  SQL*Plus (Oracle!) is the basic tool to submit SQL commands (available on all CERN platforms).
  • 22.
    Summary What is SQL Historyof SQL SQL Commands PRIMARY Key Data Integrity Database Normalization SQL Data types
  • 23.
    References Go to http://sqlcourse.com/drop.html http://sqlcourse.com/insert.html http://www.benthicsoftware.com/  Sprouse, W. and Anderson, A. B. Land Condition Trend Analysis (LCTA)  Simply Easy Learning by tutorialspoint.com