SlideShare a Scribd company logo
1 of 64
SQL/200

                     SQL Programming

            Workshop 3 – Modifying Data, Managing the
                           Database

Bookstore                   SQL200 Module 3             1
SQL200 Contact Information



            P.O. Box 6142
            Laguna Niguel, CA 92607
            949-489-1472
            http://www.d2associates.com
            slides.1@dhdursoassociates.com
            Copyright 2001-2009. All rights reserved.


Bookstore                             SQL200 Module 3   2
SQL200 Module 3
•   Part 1 – Modifying Data
    Part 2 – Managing Database Structures
•
•   Part 3 – Creating Views and Indexes
•   Part 4 -- Security




Bookstore          SQL200 Module 3          3
SQL/200

            SQL Programming

            Part 1 – Modifying Data


Bookstore          SQL200 Module 3    4
Relational Database with constraints (from text)




Bookstore                 SQL200 Module 3                  5
Data Modification Statements

            • Insert

            • Update

            • Delete



Bookstore          SQL200 Module 3   6
Data Modification Statements

            • End-user rarely sees these
              statements

            • Application developer prepares
              these statements “behind the
              scenes” based on forms filled out
              by user



Bookstore                  SQL200 Module 3        7
Insert
• Adds new rows to an existing table
• Two forms:
      – Single Row
      – Multi-Row




Bookstore            SQL200 Module 3   8
Single Row Insert


            Basic Syntax:
            Insert [into] <table-name>
            Values (<value-list>)




Bookstore                SQL200 Module 3   9
Single Row Insert

         Basic Example:
         insert into sources(source_numb,
         source_name, source_street)
         values(22,'Specialty Books',
         'Canal Street')




Bookstore             SQL200 Module 3       10
Insert Statement




Bookstore        SQL200 Module 3   11
Sources table after Insert




Bookstore            SQL200 Module 3     12
Multi-row Insert
            Basic Syntax:


            Insert [into] <table-name>
            Select <select-statement>


            We will do this after creating a new
            table later in this module
Bookstore                 SQL200 Module 3          13
Update
• Updates fields in an existing row

   Basic Syntax:
   Update <table-name>
   Set <field1> = new value, <field2> = new value,
   …
   Where <selection-criteria>
Bookstore             SQL200 Module 3                14
Update
• Increase Ingram prices by 10%

   Example:
   Update books
   Set retail_price = retail_price
   *1.10
   Where source_numb = 1
Bookstore         SQL200 Module 3    15
Ingram Book Prices before Update




Bookstore       SQL200 Module 3       16
Ingram Book Prices after Update




Bookstore   SQL200 Module 3   17
After update in MS Access




Bookstore                SQL200 Module 3   18
Delete
• Deletes one or more rows

            Basic Syntax:


            Delete from <table-name>
            Where <selection-criteria>


Bookstore                   SQL200 Module 3   19
Delete

         Example:


         Delete from sources
         Where source_numb = 22


Bookstore             SQL200 Module 3   20
Delete




Bookstore   SQL200 Module 3   21
Sources table after Delete




Bookstore             SQL200 Module 3    22
Delete and Referential Integrity
• Can affect referential integrity when deleting a
  “parent” row
• Can do following with child…
      –     Cascade: delete the child row
      –     Set null: set the child’s foreign key null
      –     Set default: as above but to default value
      –     No action: don’t allow delete of parent row
• Referential integrity can be established when
  creating or modifying table structures which we
  will look at later in the class

Bookstore                      SQL200 Module 3            23
SQL/200

                  SQL Programming

            Part 2– Managing Database Structures


Bookstore                 SQL200 Module 3          24
Schemas
• Logical view of a database; sort of a “sub-
  database” – we will not cover these in this module
  or…
      – Catalogs
      – Clusters
      – Domains (somewhat like a user defined datatype)
• These topics are highly dependent upon the vendor
  DBMS and installation practices


Bookstore                 SQL200 Module 3                 25
Tables

            • Base tables
            • Temporary tables
              – Local (or module scope)
              – Global (session scope)




Bookstore               SQL200 Module 3   26
Creating Tables
• Use create statement
• Specify:
      – Columns with data types and column
        constraints
      – Table constraints
            • Foreign key references
            • Primary key designation



Bookstore                    SQL200 Module 3   27
Temporary Tables

   Basic syntax:
   Create [global] temporary table <table-name>
   <rest of statement as for normal create>


   Note: SQL Server uses a different syntax. Put a
   #in front of the table name as in #mytable.
   Access doesn’t have true temporary tables.
Bookstore              SQL200 Module 3               28
Data Types
• Int – integers or whole numbers
      – Ex: how_many int
• Char – fixed length fields
      – Ex: state char(2)
• Varchar/Varchar2 – variable length fields
      – Ex: address varchar(35)
• Money – money field; same as MS Access
  currency
• Date/Datetime – date and time
• And many others – see documentation or Help
Bookstore                   SQL200 Module 3     29
Create Table
     Basic syntax:
     Create table <table-name>
     <column1> <datatype> <constraints>
     ,.. <column1> <datatype> <constraints>
     …
     <table constraints>
     Note: often preceded by a drop
Bookstore                  SQL200 Module 3    30
Column Constraints
•   Primary key
    Not NULL
•
•   CHECK clause
•   Default
    Unique
•



Bookstore          SQL200 Module 3   31
Table Constraints
• Primary Key
• Foreign Key
• Compare fields against each other. I.e.
  ship_date >= order_date




Bookstore          SQL200 Module 3          32
But first – the Drop Statement
• Deletes a database “object”
      –     Drop table <table-name>
      –     Drop view <view-name>
      –     Drop index <index-name>
      –     Drop domain <domain-name>




Bookstore                SQL200 Module 3   33
Create Table
       Example 1: Create a summary table
       Create table summary(
       isbn varchar(20) primary key,
       How_many int check (how_many >= 0),
       Constraint isbn_fk
       Foreign key (isbn) references
       books(isbn)
       )
Bookstore             SQL200 Module 3        34
Create Summary Table




Bookstore          SQL200 Module 3   35
Constraints on Summary Table




Bookstore     SQL200 Module 3     36
Multi-row Insert


            Basic Syntax:


            Insert [into] <table-name>
            Select <select-statement>



Bookstore                SQL200 Module 3   37
Multi-row Insert
            Basic Example: (store # times each
            book ordered)


            Insert into
            summary(isbn, how_many)
            Select isbn, count(*)
            From orderlines
            Group by isbn;
Bookstore                   SQL200 Module 3      38
Multi-row Insert




Bookstore        SQL200 Module 3   39
After multi-row insert in MS Access




Bookstore               SQL200 Module 3   40
SQL/200

                  SQL Programming

       Part 3 – Creating Views and Indexes, Modifying
                          Structures

Bookstore                 SQL200 Module 3               41
Views
• Think of a view as a named query wherein
  the definition is stored in the database
• Can be read like a table
• Some are updateable




Bookstore        SQL200 Module 3             42
Views

   Basic syntax:
   Create view <view-name> (<column-list>)
   As
   <select statement>



Bookstore               SQL200 Module 3      43
Creating a View




Bookstore       SQL200 Module 3   44
Using Views
• Can be used like a table subject to various
  limitations
      – Cannot insert into grouped queries, etc.
      – Etc.
• Sample syntax:
            select column-list
            from employee_view


Bookstore                 SQL200 Module 3          45
Using a View




Bookstore      SQL200 Module 3   46
Indexes
• Used to speed searches, joins, etc.
• Placed on:
      – primary and foreign keys
      – Secondary keys
• In commercial practice often managed by
  DBA’s for large databases



Bookstore              SQL200 Module 3      47
Indexes
    Basic syntax:


    Create [unique] index <index-name>
    On <table-name> (field-name> [desc])


    Note: can place index on a composite key; ex: state and
    city
Bookstore                 SQL200 Module 3                     48
Indexes

      Basic example:


      create index state_inx
      on customers(customer_state)



Bookstore              SQL200 Module 3   49
After indexing on customer_state




Bookstore              SQL200 Module 3   50
Customers table with index




Bookstore         SQL200 Module 3    51
State_inx in Oracle




Bookstore         SQL200 Module 3   52
Modifying a Table Design
• Applies to tables
• Use ALTER statement
      –     Add columns
      –     Delete columns
      –     Rename columns
      –     Add column constraints
      –     Add table constraints


Bookstore                  SQL200 Module 3   53
Modifying a Table Design
      Basic syntax:
      Alter <table-name>
      Add <field-name>,
      Add <table-constraint>,
      Modify <field-name>
      Etc.

Bookstore               SQL200 Module 3   54
Modify a Table Design

        Example: add a phone number field


        alter table publishers
        add phone char(12);




Bookstore               SQL200 Module 3     55
After alter publishers table




Bookstore               SQL200 Module 3   56
SQL/200

            SQL Programming

              Part 4 – Security


Bookstore         SQL200 Module 3   57
Security
•   Specifics can vary by product
    Access: workgroup administrator
•
•   SQL Server: users, groups
•   Oracle: users, roles




Bookstore          SQL200 Module 3    58
Security
• Important DBA function
      – Beyond scope of this course
      – Typically controlled through the Enterprise
        Managers
• In commercial practice application security
  frequently controlled via own login and a
  “users” table or similar


Bookstore               SQL200 Module 3               59
SQL Security Statements


              • Grant
              • Revoke
              • Deny




Bookstore            SQL200 Module 3   60
Grant

   Syntax:


   Grant <access-right> [with grant option]
   On <object> to <user>


Bookstore           SQL200 Module 3           61
Access Rights
•   Select
    Update
•
•   Insert
•   Delete
    References
•
•   All privileges


Bookstore            SQL200 Module 3   62
Grant

     Example:


     Grant update
     On employees to ddurso



Bookstore           SQL200 Module 3   63
Revoke
• Revokes the rights
• Syntax similar to grant




                                    [end module]
Bookstore         SQL200 Module 3                  64

More Related Content

What's hot (19)

The Ring programming language version 1.10 book - Part 36 of 212
The Ring programming language version 1.10 book - Part 36 of 212The Ring programming language version 1.10 book - Part 36 of 212
The Ring programming language version 1.10 book - Part 36 of 212
 
Lab
LabLab
Lab
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
 
Dbms practical list
Dbms practical listDbms practical list
Dbms practical list
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
Les11 Including Constraints
Les11 Including ConstraintsLes11 Including Constraints
Les11 Including Constraints
 
Schema webinar
Schema webinarSchema webinar
Schema webinar
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2
 
The Ring programming language version 1.5.1 book - Part 26 of 180
The Ring programming language version 1.5.1 book - Part 26 of 180The Ring programming language version 1.5.1 book - Part 26 of 180
The Ring programming language version 1.5.1 book - Part 26 of 180
 
Schema201 webinar
Schema201 webinarSchema201 webinar
Schema201 webinar
 
Blocks In Drupal
Blocks In DrupalBlocks In Drupal
Blocks In Drupal
 
Sql presentation 1 by chandan
Sql presentation 1 by chandanSql presentation 1 by chandan
Sql presentation 1 by chandan
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
 
Dbms record
Dbms recordDbms record
Dbms record
 
The Ring programming language version 1.2 book - Part 17 of 84
The Ring programming language version 1.2 book - Part 17 of 84The Ring programming language version 1.2 book - Part 17 of 84
The Ring programming language version 1.2 book - Part 17 of 84
 
Navicat en
Navicat enNavicat en
Navicat en
 
Sql views
Sql viewsSql views
Sql views
 
MySQL and its basic commands
MySQL and its basic commandsMySQL and its basic commands
MySQL and its basic commands
 
SQL
SQLSQL
SQL
 

Viewers also liked

AMP110 Microsoft Access Macros
AMP110 Microsoft Access MacrosAMP110 Microsoft Access Macros
AMP110 Microsoft Access MacrosDan D'Urso
 
Muziekdigitaal Taggerfm Pitch 091027
Muziekdigitaal Taggerfm Pitch 091027Muziekdigitaal Taggerfm Pitch 091027
Muziekdigitaal Taggerfm Pitch 091027Tim Rootsaert
 
Muziekdigitaal Mike Belgium Pitch 091028
Muziekdigitaal Mike Belgium Pitch 091028Muziekdigitaal Mike Belgium Pitch 091028
Muziekdigitaal Mike Belgium Pitch 091028Tim Rootsaert
 
Tagger.fm Muziek Digitaal 091028
Tagger.fm Muziek Digitaal 091028Tagger.fm Muziek Digitaal 091028
Tagger.fm Muziek Digitaal 091028Tim Rootsaert
 
Il Mostro Di Cogne
Il Mostro Di CogneIl Mostro Di Cogne
Il Mostro Di CogneF R
 
Creating a Photo Story With Soundslides
Creating a Photo Story With SoundslidesCreating a Photo Story With Soundslides
Creating a Photo Story With SoundslidesRyan Thornburg
 
AVB201.1 Microsoft Access VBA Module 1
AVB201.1 Microsoft Access VBA Module 1AVB201.1 Microsoft Access VBA Module 1
AVB201.1 Microsoft Access VBA Module 1Dan D'Urso
 
Microsoft access self joins
Microsoft access self joinsMicrosoft access self joins
Microsoft access self joinsDan D'Urso
 
電動車及儲能系統產業發展-創業懶人包-青年創業及圓夢網
電動車及儲能系統產業發展-創業懶人包-青年創業及圓夢網電動車及儲能系統產業發展-創業懶人包-青年創業及圓夢網
電動車及儲能系統產業發展-創業懶人包-青年創業及圓夢網RICK Lin
 
Thom Point of View on Segmentation
Thom Point of View on SegmentationThom Point of View on Segmentation
Thom Point of View on SegmentationPieterDuron
 
My Print Portfolio
My Print PortfolioMy Print Portfolio
My Print Portfoliobeth7865
 
SQL200.1 Module 1
SQL200.1 Module 1SQL200.1 Module 1
SQL200.1 Module 1Dan D'Urso
 

Viewers also liked (20)

AMP110 Microsoft Access Macros
AMP110 Microsoft Access MacrosAMP110 Microsoft Access Macros
AMP110 Microsoft Access Macros
 
PREMIS FOTOGRAFIA FILOSOFICA
PREMIS FOTOGRAFIA FILOSOFICAPREMIS FOTOGRAFIA FILOSOFICA
PREMIS FOTOGRAFIA FILOSOFICA
 
Muziekdigitaal Taggerfm Pitch 091027
Muziekdigitaal Taggerfm Pitch 091027Muziekdigitaal Taggerfm Pitch 091027
Muziekdigitaal Taggerfm Pitch 091027
 
Muziekdigitaal Mike Belgium Pitch 091028
Muziekdigitaal Mike Belgium Pitch 091028Muziekdigitaal Mike Belgium Pitch 091028
Muziekdigitaal Mike Belgium Pitch 091028
 
Tagger.fm Muziek Digitaal 091028
Tagger.fm Muziek Digitaal 091028Tagger.fm Muziek Digitaal 091028
Tagger.fm Muziek Digitaal 091028
 
Profit Hunters
Profit HuntersProfit Hunters
Profit Hunters
 
Il Mostro Di Cogne
Il Mostro Di CogneIl Mostro Di Cogne
Il Mostro Di Cogne
 
Roma 2014
Roma 2014Roma 2014
Roma 2014
 
Creating a Photo Story With Soundslides
Creating a Photo Story With SoundslidesCreating a Photo Story With Soundslides
Creating a Photo Story With Soundslides
 
AVB201.1 Microsoft Access VBA Module 1
AVB201.1 Microsoft Access VBA Module 1AVB201.1 Microsoft Access VBA Module 1
AVB201.1 Microsoft Access VBA Module 1
 
AIN100
AIN100AIN100
AIN100
 
13 concurs d'aforismes
13 concurs d'aforismes13 concurs d'aforismes
13 concurs d'aforismes
 
Farrah bostic 5for5
Farrah bostic 5for5Farrah bostic 5for5
Farrah bostic 5for5
 
Microsoft access self joins
Microsoft access self joinsMicrosoft access self joins
Microsoft access self joins
 
電動車及儲能系統產業發展-創業懶人包-青年創業及圓夢網
電動車及儲能系統產業發展-創業懶人包-青年創業及圓夢網電動車及儲能系統產業發展-創業懶人包-青年創業及圓夢網
電動車及儲能系統產業發展-創業懶人包-青年創業及圓夢網
 
Thom Point of View on Segmentation
Thom Point of View on SegmentationThom Point of View on Segmentation
Thom Point of View on Segmentation
 
My Print Portfolio
My Print PortfolioMy Print Portfolio
My Print Portfolio
 
SQL200.1 Module 1
SQL200.1 Module 1SQL200.1 Module 1
SQL200.1 Module 1
 
¿Somos animales?
¿Somos animales?¿Somos animales?
¿Somos animales?
 
Filoarnaucadell
Filoarnaucadell Filoarnaucadell
Filoarnaucadell
 

Similar to SQL200.3 Module 3

SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3Dan D'Urso
 
SQL212.3 Introduction to SQL using Oracle Module 3
SQL212.3 Introduction to SQL using Oracle Module 3SQL212.3 Introduction to SQL using Oracle Module 3
SQL212.3 Introduction to SQL using Oracle Module 3Dan D'Urso
 
SQL202.2 Accelerated Introduction to SQL Using SQL Server Module 2
SQL202.2 Accelerated Introduction to SQL Using SQL Server Module 2SQL202.2 Accelerated Introduction to SQL Using SQL Server Module 2
SQL202.2 Accelerated Introduction to SQL Using SQL Server Module 2Dan D'Urso
 
SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1
SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1
SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1Dan D'Urso
 
SQL Server 2008 New Features
SQL Server 2008 New FeaturesSQL Server 2008 New Features
SQL Server 2008 New FeaturesDan English
 
SQL302 Intermediate SQL Workshop 3
SQL302 Intermediate SQL Workshop 3SQL302 Intermediate SQL Workshop 3
SQL302 Intermediate SQL Workshop 3Dan D'Urso
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsAlex Zaballa
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsAlex Zaballa
 
SQL212.1 Introduction to SQL using Oracle Module 1
SQL212.1 Introduction to SQL using Oracle Module 1SQL212.1 Introduction to SQL using Oracle Module 1
SQL212.1 Introduction to SQL using Oracle Module 1Dan D'Urso
 
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1MariaDB plc
 
SQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxSQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxKashifManzoorMeo
 
Getting Started with MySQL II
Getting Started with MySQL IIGetting Started with MySQL II
Getting Started with MySQL IISankhya_Analytics
 
SQL200A Microsoft Access SQL Design
SQL200A Microsoft Access SQL DesignSQL200A Microsoft Access SQL Design
SQL200A Microsoft Access SQL DesignDan D'Urso
 
SQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxSQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxQuyVo27
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro projectARVIND SARDAR
 
SQL212.2 Introduction to SQL using Oracle Module 2
SQL212.2 Introduction to SQL using Oracle Module 2SQL212.2 Introduction to SQL using Oracle Module 2
SQL212.2 Introduction to SQL using Oracle Module 2Dan D'Urso
 
RivieraJUG - MySQL 8.0 - What's new for developers.pdf
RivieraJUG - MySQL 8.0 - What's new for developers.pdfRivieraJUG - MySQL 8.0 - What's new for developers.pdf
RivieraJUG - MySQL 8.0 - What's new for developers.pdfFrederic Descamps
 

Similar to SQL200.3 Module 3 (20)

SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
 
SQL212.3 Introduction to SQL using Oracle Module 3
SQL212.3 Introduction to SQL using Oracle Module 3SQL212.3 Introduction to SQL using Oracle Module 3
SQL212.3 Introduction to SQL using Oracle Module 3
 
SQL202.2 Accelerated Introduction to SQL Using SQL Server Module 2
SQL202.2 Accelerated Introduction to SQL Using SQL Server Module 2SQL202.2 Accelerated Introduction to SQL Using SQL Server Module 2
SQL202.2 Accelerated Introduction to SQL Using SQL Server Module 2
 
SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1
SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1
SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
Bn1037 demo oracle sql
Bn1037 demo  oracle sqlBn1037 demo  oracle sql
Bn1037 demo oracle sql
 
SQL Server 2008 New Features
SQL Server 2008 New FeaturesSQL Server 2008 New Features
SQL Server 2008 New Features
 
SQL302 Intermediate SQL Workshop 3
SQL302 Intermediate SQL Workshop 3SQL302 Intermediate SQL Workshop 3
SQL302 Intermediate SQL Workshop 3
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
SQL212.1 Introduction to SQL using Oracle Module 1
SQL212.1 Introduction to SQL using Oracle Module 1SQL212.1 Introduction to SQL using Oracle Module 1
SQL212.1 Introduction to SQL using Oracle Module 1
 
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
 
SQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxSQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptx
 
Getting Started with MySQL II
Getting Started with MySQL IIGetting Started with MySQL II
Getting Started with MySQL II
 
SQL200A Microsoft Access SQL Design
SQL200A Microsoft Access SQL DesignSQL200A Microsoft Access SQL Design
SQL200A Microsoft Access SQL Design
 
SQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxSQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptx
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro project
 
SQL212.2 Introduction to SQL using Oracle Module 2
SQL212.2 Introduction to SQL using Oracle Module 2SQL212.2 Introduction to SQL using Oracle Module 2
SQL212.2 Introduction to SQL using Oracle Module 2
 
RivieraJUG - MySQL 8.0 - What's new for developers.pdf
RivieraJUG - MySQL 8.0 - What's new for developers.pdfRivieraJUG - MySQL 8.0 - What's new for developers.pdf
RivieraJUG - MySQL 8.0 - What's new for developers.pdf
 

More from Dan D'Urso

SQL201S Accelerated Introduction to MySQL Queries
SQL201S Accelerated Introduction to MySQL QueriesSQL201S Accelerated Introduction to MySQL Queries
SQL201S Accelerated Introduction to MySQL QueriesDan D'Urso
 
LCD201d Database Diagramming with Lucidchart
LCD201d Database Diagramming with LucidchartLCD201d Database Diagramming with Lucidchart
LCD201d Database Diagramming with LucidchartDan D'Urso
 
Database Normalization
Database NormalizationDatabase Normalization
Database NormalizationDan D'Urso
 
VIS201d Visio Database Diagramming
VIS201d Visio Database DiagrammingVIS201d Visio Database Diagramming
VIS201d Visio Database DiagrammingDan D'Urso
 
PRJ101a Project 2013 Accelerated
PRJ101a Project 2013 AcceleratedPRJ101a Project 2013 Accelerated
PRJ101a Project 2013 AcceleratedDan D'Urso
 
PRJ101xl Project Libre Basic Training
PRJ101xl Project Libre Basic TrainingPRJ101xl Project Libre Basic Training
PRJ101xl Project Libre Basic TrainingDan D'Urso
 
Introduction to coding using Python
Introduction to coding using PythonIntroduction to coding using Python
Introduction to coding using PythonDan D'Urso
 
Stem conference
Stem conferenceStem conference
Stem conferenceDan D'Urso
 
SQL302 Intermediate SQL
SQL302 Intermediate SQLSQL302 Intermediate SQL
SQL302 Intermediate SQLDan D'Urso
 
AIN106 Access Reporting and Analysis
AIN106 Access Reporting and AnalysisAIN106 Access Reporting and Analysis
AIN106 Access Reporting and AnalysisDan D'Urso
 
SQL302 Intermediate SQL Workshop 2
SQL302 Intermediate SQL Workshop 2SQL302 Intermediate SQL Workshop 2
SQL302 Intermediate SQL Workshop 2Dan D'Urso
 
Course Catalog
Course CatalogCourse Catalog
Course CatalogDan D'Urso
 
SQL302 Intermediate SQL Workshop 1
SQL302 Intermediate SQL Workshop 1SQL302 Intermediate SQL Workshop 1
SQL302 Intermediate SQL Workshop 1Dan D'Urso
 
SQL212 Oracle SQL Manual
SQL212 Oracle SQL ManualSQL212 Oracle SQL Manual
SQL212 Oracle SQL ManualDan D'Urso
 
SQL201W MySQL SQL Manual
SQL201W MySQL SQL ManualSQL201W MySQL SQL Manual
SQL201W MySQL SQL ManualDan D'Urso
 
SQL206 SQL Median
SQL206 SQL MedianSQL206 SQL Median
SQL206 SQL MedianDan D'Urso
 
SQL202 SQL Server SQL Manual
SQL202 SQL Server SQL ManualSQL202 SQL Server SQL Manual
SQL202 SQL Server SQL ManualDan D'Urso
 
AIN102 Microsoft Access Queries
AIN102 Microsoft Access QueriesAIN102 Microsoft Access Queries
AIN102 Microsoft Access QueriesDan D'Urso
 
AIN102S Access string function sample queries
AIN102S Access string function sample queriesAIN102S Access string function sample queries
AIN102S Access string function sample queriesDan D'Urso
 
AIN102.2 Microsoft Access Queries
AIN102.2 Microsoft Access QueriesAIN102.2 Microsoft Access Queries
AIN102.2 Microsoft Access QueriesDan D'Urso
 

More from Dan D'Urso (20)

SQL201S Accelerated Introduction to MySQL Queries
SQL201S Accelerated Introduction to MySQL QueriesSQL201S Accelerated Introduction to MySQL Queries
SQL201S Accelerated Introduction to MySQL Queries
 
LCD201d Database Diagramming with Lucidchart
LCD201d Database Diagramming with LucidchartLCD201d Database Diagramming with Lucidchart
LCD201d Database Diagramming with Lucidchart
 
Database Normalization
Database NormalizationDatabase Normalization
Database Normalization
 
VIS201d Visio Database Diagramming
VIS201d Visio Database DiagrammingVIS201d Visio Database Diagramming
VIS201d Visio Database Diagramming
 
PRJ101a Project 2013 Accelerated
PRJ101a Project 2013 AcceleratedPRJ101a Project 2013 Accelerated
PRJ101a Project 2013 Accelerated
 
PRJ101xl Project Libre Basic Training
PRJ101xl Project Libre Basic TrainingPRJ101xl Project Libre Basic Training
PRJ101xl Project Libre Basic Training
 
Introduction to coding using Python
Introduction to coding using PythonIntroduction to coding using Python
Introduction to coding using Python
 
Stem conference
Stem conferenceStem conference
Stem conference
 
SQL302 Intermediate SQL
SQL302 Intermediate SQLSQL302 Intermediate SQL
SQL302 Intermediate SQL
 
AIN106 Access Reporting and Analysis
AIN106 Access Reporting and AnalysisAIN106 Access Reporting and Analysis
AIN106 Access Reporting and Analysis
 
SQL302 Intermediate SQL Workshop 2
SQL302 Intermediate SQL Workshop 2SQL302 Intermediate SQL Workshop 2
SQL302 Intermediate SQL Workshop 2
 
Course Catalog
Course CatalogCourse Catalog
Course Catalog
 
SQL302 Intermediate SQL Workshop 1
SQL302 Intermediate SQL Workshop 1SQL302 Intermediate SQL Workshop 1
SQL302 Intermediate SQL Workshop 1
 
SQL212 Oracle SQL Manual
SQL212 Oracle SQL ManualSQL212 Oracle SQL Manual
SQL212 Oracle SQL Manual
 
SQL201W MySQL SQL Manual
SQL201W MySQL SQL ManualSQL201W MySQL SQL Manual
SQL201W MySQL SQL Manual
 
SQL206 SQL Median
SQL206 SQL MedianSQL206 SQL Median
SQL206 SQL Median
 
SQL202 SQL Server SQL Manual
SQL202 SQL Server SQL ManualSQL202 SQL Server SQL Manual
SQL202 SQL Server SQL Manual
 
AIN102 Microsoft Access Queries
AIN102 Microsoft Access QueriesAIN102 Microsoft Access Queries
AIN102 Microsoft Access Queries
 
AIN102S Access string function sample queries
AIN102S Access string function sample queriesAIN102S Access string function sample queries
AIN102S Access string function sample queries
 
AIN102.2 Microsoft Access Queries
AIN102.2 Microsoft Access QueriesAIN102.2 Microsoft Access Queries
AIN102.2 Microsoft Access Queries
 

Recently uploaded

Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 

Recently uploaded (20)

Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 

SQL200.3 Module 3

  • 1. SQL/200 SQL Programming Workshop 3 – Modifying Data, Managing the Database Bookstore SQL200 Module 3 1
  • 2. SQL200 Contact Information P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 http://www.d2associates.com slides.1@dhdursoassociates.com Copyright 2001-2009. All rights reserved. Bookstore SQL200 Module 3 2
  • 3. SQL200 Module 3 • Part 1 – Modifying Data Part 2 – Managing Database Structures • • Part 3 – Creating Views and Indexes • Part 4 -- Security Bookstore SQL200 Module 3 3
  • 4. SQL/200 SQL Programming Part 1 – Modifying Data Bookstore SQL200 Module 3 4
  • 5. Relational Database with constraints (from text) Bookstore SQL200 Module 3 5
  • 6. Data Modification Statements • Insert • Update • Delete Bookstore SQL200 Module 3 6
  • 7. Data Modification Statements • End-user rarely sees these statements • Application developer prepares these statements “behind the scenes” based on forms filled out by user Bookstore SQL200 Module 3 7
  • 8. Insert • Adds new rows to an existing table • Two forms: – Single Row – Multi-Row Bookstore SQL200 Module 3 8
  • 9. Single Row Insert Basic Syntax: Insert [into] <table-name> Values (<value-list>) Bookstore SQL200 Module 3 9
  • 10. Single Row Insert Basic Example: insert into sources(source_numb, source_name, source_street) values(22,'Specialty Books', 'Canal Street') Bookstore SQL200 Module 3 10
  • 11. Insert Statement Bookstore SQL200 Module 3 11
  • 12. Sources table after Insert Bookstore SQL200 Module 3 12
  • 13. Multi-row Insert Basic Syntax: Insert [into] <table-name> Select <select-statement> We will do this after creating a new table later in this module Bookstore SQL200 Module 3 13
  • 14. Update • Updates fields in an existing row Basic Syntax: Update <table-name> Set <field1> = new value, <field2> = new value, … Where <selection-criteria> Bookstore SQL200 Module 3 14
  • 15. Update • Increase Ingram prices by 10% Example: Update books Set retail_price = retail_price *1.10 Where source_numb = 1 Bookstore SQL200 Module 3 15
  • 16. Ingram Book Prices before Update Bookstore SQL200 Module 3 16
  • 17. Ingram Book Prices after Update Bookstore SQL200 Module 3 17
  • 18. After update in MS Access Bookstore SQL200 Module 3 18
  • 19. Delete • Deletes one or more rows Basic Syntax: Delete from <table-name> Where <selection-criteria> Bookstore SQL200 Module 3 19
  • 20. Delete Example: Delete from sources Where source_numb = 22 Bookstore SQL200 Module 3 20
  • 21. Delete Bookstore SQL200 Module 3 21
  • 22. Sources table after Delete Bookstore SQL200 Module 3 22
  • 23. Delete and Referential Integrity • Can affect referential integrity when deleting a “parent” row • Can do following with child… – Cascade: delete the child row – Set null: set the child’s foreign key null – Set default: as above but to default value – No action: don’t allow delete of parent row • Referential integrity can be established when creating or modifying table structures which we will look at later in the class Bookstore SQL200 Module 3 23
  • 24. SQL/200 SQL Programming Part 2– Managing Database Structures Bookstore SQL200 Module 3 24
  • 25. Schemas • Logical view of a database; sort of a “sub- database” – we will not cover these in this module or… – Catalogs – Clusters – Domains (somewhat like a user defined datatype) • These topics are highly dependent upon the vendor DBMS and installation practices Bookstore SQL200 Module 3 25
  • 26. Tables • Base tables • Temporary tables – Local (or module scope) – Global (session scope) Bookstore SQL200 Module 3 26
  • 27. Creating Tables • Use create statement • Specify: – Columns with data types and column constraints – Table constraints • Foreign key references • Primary key designation Bookstore SQL200 Module 3 27
  • 28. Temporary Tables Basic syntax: Create [global] temporary table <table-name> <rest of statement as for normal create> Note: SQL Server uses a different syntax. Put a #in front of the table name as in #mytable. Access doesn’t have true temporary tables. Bookstore SQL200 Module 3 28
  • 29. Data Types • Int – integers or whole numbers – Ex: how_many int • Char – fixed length fields – Ex: state char(2) • Varchar/Varchar2 – variable length fields – Ex: address varchar(35) • Money – money field; same as MS Access currency • Date/Datetime – date and time • And many others – see documentation or Help Bookstore SQL200 Module 3 29
  • 30. Create Table Basic syntax: Create table <table-name> <column1> <datatype> <constraints> ,.. <column1> <datatype> <constraints> … <table constraints> Note: often preceded by a drop Bookstore SQL200 Module 3 30
  • 31. Column Constraints • Primary key Not NULL • • CHECK clause • Default Unique • Bookstore SQL200 Module 3 31
  • 32. Table Constraints • Primary Key • Foreign Key • Compare fields against each other. I.e. ship_date >= order_date Bookstore SQL200 Module 3 32
  • 33. But first – the Drop Statement • Deletes a database “object” – Drop table <table-name> – Drop view <view-name> – Drop index <index-name> – Drop domain <domain-name> Bookstore SQL200 Module 3 33
  • 34. Create Table Example 1: Create a summary table Create table summary( isbn varchar(20) primary key, How_many int check (how_many >= 0), Constraint isbn_fk Foreign key (isbn) references books(isbn) ) Bookstore SQL200 Module 3 34
  • 35. Create Summary Table Bookstore SQL200 Module 3 35
  • 36. Constraints on Summary Table Bookstore SQL200 Module 3 36
  • 37. Multi-row Insert Basic Syntax: Insert [into] <table-name> Select <select-statement> Bookstore SQL200 Module 3 37
  • 38. Multi-row Insert Basic Example: (store # times each book ordered) Insert into summary(isbn, how_many) Select isbn, count(*) From orderlines Group by isbn; Bookstore SQL200 Module 3 38
  • 39. Multi-row Insert Bookstore SQL200 Module 3 39
  • 40. After multi-row insert in MS Access Bookstore SQL200 Module 3 40
  • 41. SQL/200 SQL Programming Part 3 – Creating Views and Indexes, Modifying Structures Bookstore SQL200 Module 3 41
  • 42. Views • Think of a view as a named query wherein the definition is stored in the database • Can be read like a table • Some are updateable Bookstore SQL200 Module 3 42
  • 43. Views Basic syntax: Create view <view-name> (<column-list>) As <select statement> Bookstore SQL200 Module 3 43
  • 44. Creating a View Bookstore SQL200 Module 3 44
  • 45. Using Views • Can be used like a table subject to various limitations – Cannot insert into grouped queries, etc. – Etc. • Sample syntax: select column-list from employee_view Bookstore SQL200 Module 3 45
  • 46. Using a View Bookstore SQL200 Module 3 46
  • 47. Indexes • Used to speed searches, joins, etc. • Placed on: – primary and foreign keys – Secondary keys • In commercial practice often managed by DBA’s for large databases Bookstore SQL200 Module 3 47
  • 48. Indexes Basic syntax: Create [unique] index <index-name> On <table-name> (field-name> [desc]) Note: can place index on a composite key; ex: state and city Bookstore SQL200 Module 3 48
  • 49. Indexes Basic example: create index state_inx on customers(customer_state) Bookstore SQL200 Module 3 49
  • 50. After indexing on customer_state Bookstore SQL200 Module 3 50
  • 51. Customers table with index Bookstore SQL200 Module 3 51
  • 52. State_inx in Oracle Bookstore SQL200 Module 3 52
  • 53. Modifying a Table Design • Applies to tables • Use ALTER statement – Add columns – Delete columns – Rename columns – Add column constraints – Add table constraints Bookstore SQL200 Module 3 53
  • 54. Modifying a Table Design Basic syntax: Alter <table-name> Add <field-name>, Add <table-constraint>, Modify <field-name> Etc. Bookstore SQL200 Module 3 54
  • 55. Modify a Table Design Example: add a phone number field alter table publishers add phone char(12); Bookstore SQL200 Module 3 55
  • 56. After alter publishers table Bookstore SQL200 Module 3 56
  • 57. SQL/200 SQL Programming Part 4 – Security Bookstore SQL200 Module 3 57
  • 58. Security • Specifics can vary by product Access: workgroup administrator • • SQL Server: users, groups • Oracle: users, roles Bookstore SQL200 Module 3 58
  • 59. Security • Important DBA function – Beyond scope of this course – Typically controlled through the Enterprise Managers • In commercial practice application security frequently controlled via own login and a “users” table or similar Bookstore SQL200 Module 3 59
  • 60. SQL Security Statements • Grant • Revoke • Deny Bookstore SQL200 Module 3 60
  • 61. Grant Syntax: Grant <access-right> [with grant option] On <object> to <user> Bookstore SQL200 Module 3 61
  • 62. Access Rights • Select Update • • Insert • Delete References • • All privileges Bookstore SQL200 Module 3 62
  • 63. Grant Example: Grant update On employees to ddurso Bookstore SQL200 Module 3 63
  • 64. Revoke • Revokes the rights • Syntax similar to grant [end module] Bookstore SQL200 Module 3 64