Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture # 24 Introduction to SQL Muhammad Emran Database Systems.

Similar presentations


Presentation on theme: "Lecture # 24 Introduction to SQL Muhammad Emran Database Systems."— Presentation transcript:

1 Lecture # 24 Introduction to SQL Muhammad Emran Database Systems

2 2 Objectives Definition of terms Definition of terms Discuss advantages of standardized SQL Discuss advantages of standardized SQL Define a database using SQL data definition language Define a database using SQL data definition language Write single table queries using SQL Write single table queries using SQL Establish referential integrity using SQL Establish referential integrity using SQL Work with Views Work with Views

3 3 The Physical Design Stage of SDLC (Figures 2-4, 2-5 revisited) Purpose –programming, testing, training, installation, documenting Deliverable – operational programs, documentation, training materials, program/data structures Database activity – physical database design and database implementation Project Identification and Selection Project Initiation and Planning Analysis Physical Design Implementation Maintenance Logical Design Implementation Physical Design

4 4 SQL Overview Structured Query Language Structured Query Language The standard for relational database management systems (RDBMS) The standard for relational database management systems (RDBMS) SQL-92 (Also call SQL-2) and SQL-99 Standards – Purpose: SQL-92 (Also call SQL-2) and SQL-99 Standards – Purpose: Specify syntax/semantics for data definition and manipulation Specify syntax/semantics for data definition and manipulation Define data structures Define data structures Enable portability Enable portability Specify minimal (level 1) and complete (level 2) standards Specify minimal (level 1) and complete (level 2) standards Allow for later growth/enhancement to standard Allow for later growth/enhancement to standard

5 5 Benefits of a Standardized Relational Language Reduced training costs Reduced training costs Productivity Productivity Application portability Application portability Application longevity Application longevity Reduced dependence on a single vendor Reduced dependence on a single vendor Cross-system communication Cross-system communication

6 6 SQL Environment Catalog Catalog A set of schemas that constitute the description of a database A set of schemas that constitute the description of a database Schema Schema The structure that contains descriptions of objects created by a user (base tables, views, constraints) The structure that contains descriptions of objects created by a user (base tables, views, constraints) Data Definition Language (DDL) Data Definition Language (DDL) Commands that define a database, including creating, altering, and dropping tables and establishing constraints Commands that define a database, including creating, altering, and dropping tables and establishing constraints Data Manipulation Language (DML) Data Manipulation Language (DML) Commands that maintain and query a database Commands that maintain and query a database Data Control Language (DCL) Data Control Language (DCL) Commands that control a database, including administering privileges and committing data Commands that control a database, including administering privileges and committing data

7 7 Figure 7-1: A simplified schematic of a typical SQL environment, as described by the SQL-92 standard

8 8 Some SQL Data types (from Oracle 9i) String types String types CHAR(n) – fixed-length character data, n characters long Maximum length = 2000 bytes CHAR(n) – fixed-length character data, n characters long Maximum length = 2000 bytes VARCHAR2(n) – variable length character data, maximum 4000 bytes VARCHAR2(n) – variable length character data, maximum 4000 bytes LONG – variable-length character data, up to 4GB. Maximum 1 per table LONG – variable-length character data, up to 4GB. Maximum 1 per table Numeric types Numeric types NUMBER(p,q) – general purpose numeric data type NUMBER(p,q) – general purpose numeric data type INTEGER(p) – signed integer, p digits wide INTEGER(p) – signed integer, p digits wide FLOAT(p) – floating point in scientific notation with p binary digits precision FLOAT(p) – floating point in scientific notation with p binary digits precision Date/time type Date/time type DATE – fixed-length date/time in dd-mm-yy form DATE – fixed-length date/time in dd-mm-yy form

9 9 Figure 7-4: DDL, DML, DCL, and the database development process

10 10 SQL Database Definition Data Definition Language (DDL) Data Definition Language (DDL) Major CREATE statements: Major CREATE statements: CREATE SCHEMA – defines a portion of the database owned by a particular user CREATE SCHEMA – defines a portion of the database owned by a particular user CREATE TABLE – defines a table and its columns CREATE TABLE – defines a table and its columns CREATE VIEW – defines a logical table from one or more views CREATE VIEW – defines a logical table from one or more views Other CREATE statements: CHARACTER SET, COLLATION, TRANSLATION, ASSERTION, DOMAIN Other CREATE statements: CHARACTER SET, COLLATION, TRANSLATION, ASSERTION, DOMAIN

11 11 Table Creation Figure 7-5: General syntax for CREATE TABLE 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

12 12 The following slides create tables for this enterprise data model

13 13 Figure 7-6: SQL database definition commands for Pine Valley Furniture Overall table definitions

14 14 Defining attributes and their data types

15 15 Non-nullable specification Identifying primary key Primary keys can never have NULL values

16 16 Non-nullable specifications Primary key Some primary keys are composite – composed of multiple attributes

17 17 Default value Domain constraint Controlling the values in attributes

18 18 Primary key of parent table Identifying foreign keys and establishing relationships Foreign key of dependent table


Download ppt "Lecture # 24 Introduction to SQL Muhammad Emran Database Systems."

Similar presentations


Ads by Google