Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
33 views

Introduction To SQL

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Introduction To SQL

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

INTRODUCTION TO SQL

BY: MAILA JERRIELYN D. CALIAO


OBJECTIVES
 Define terms
 Interpret history and role of SQL
 Define a database using SQL data definition
language
SQL OVERVIEW
 Structured Query Language
 The standard for relational database management systems
(RDBMS)
 RDBMS: A database management system that manages data as a
collection of tables in which all relationships are represented by
common values in related tables
HISTORY OF SQL
 1970–E. F. Codd develops relational database concept
 1974-1979–System R with Sequel (later SQL) created at IBM Research Lab
 1979–Oracle markets first relational DB with SQL
 1981 – SQL/DS first available RDBMS system on DOS/VSE
 Others followed: INGRES (1981), IDM (1982), DG/SGL (1984), Sybase (1986)
 1986–ANSI SQL standard released
 1989, 1992, 1999, 2003, 2006, 2008–Major ANSI standard updates
 Current–SQL is supported by most major database vendors
SQL ENVIRONMENT
 Catalog
 A set of schemas that constitute the description of a database

 Schema
 The structure that contains descriptions of objects created by a user (base tables, views, constraints)

 Data Definition Language (DDL)


 Commands that define a database, including creating, altering, and dropping tables and establishing constraints

 Data Manipulation Language (DML)


 Commands that maintain and query a database

 Data Control Language (DCL)


 Commands that control a database, including administering privileges and committing data
SQL DATABASE DEFINITION

 Data Definition Language (DDL)


 Major CREATE statements:
 CREATE SCHEMA–defines a portion of the database owned by a particular user
 CREATE TABLE–defines a new table and its columns
 CREATE VIEW–defines a logical table from one or more tables or views

 Other CREATE statements:


CHARACTER SET, COLLATION,TRANSLATION, ASSERTION, DOMAIN
STEPS IN TABLE CREATION

1. Identify data types for attributes


2. Identify columns that can and cannot be null
3. Identify columns that must be unique (candidate keys)
4. Identify primary key–foreign key mates
5. Determine default values
6. Identify constraints on columns (domain specifications)
7. Create the table and associated indexes
DATA INTEGRITY CONTROLS
 Referential integrity–constraint that ensures that foreign
key values of a table must match primary key values of a
related table in 1:M relationships
 Restricting:
 Deletes of primary records
 Updates of primary records
 Inserts of dependent records
SOME OF THE MOST IMPORTANT SQL COMMANDS

 SELECT - extracts data from a database


 UPDATE - updates data in a database
 DELETE - deletes data from a database
 INSERT INTO - inserts new data into a
database
 CREATE DATABASE - creates a new database
SOME OF THE MOST IMPORTANT SQL COMMANDS

 ALTER DATABASE - modifies a database


 CREATE TABLE - creates a new table
 ALTER TABLE - modifies a table
 DROP TABLE - deletes a table
 CREATE INDEX - creates an index (search key)
 DROP INDEX - deletes an index
WHERE

 The WHERE clause is used to filter records.


 It is used to extract only those records that
fulfill a specified condition.
ORDER BY
 The ORDER BY keyword is used to sort the
result-set in ascending or descending order.
 The ORDER BY keyword sorts the records in
ascending order by default. To sort the records in
descending order, use the DESC keyword.
COUNT(), AVG() AND SUM()
 The COUNT() function returns the number
of rows that matches a specified criterion.
 The AVG() function returns the average value
of a numeric column.
 The SUM() function returns the total sum of a
numeric column.

You might also like