SlideShare a Scribd company logo
SQL/200 SQL Programming Workshop 3 – Modifying Data, Managing the Database Bookstore SQL200 Module 3 Based on  SQL Clearly Explained  by Jan Harrington
Note on SQL200 Slides These slides were originally designed to support the single SQL200 course which was used for any of MS Access, Oracle and SQL Server. As such you may see here slides developed in any one of the above products. We are in the process of migrating the Oracle slides and the MS Access slides out into their own slide sets.  These SQL200 slides (used in SQL202 as well as SQL200) will focus on Microsoft SQL Server. Bookstore SQL200 Module 3
Warning! Below are some table name changes to be aware of in doing queries. We have created synonyms so either name should work. Bookstore2 SQL200  Module 2 New Name Old Name Orders Order_filled Order_Lines Orderlines
SQL200 Contact Information Bookstore SQL200 Module 3 P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 http://www.d2associates.com [email_address]   Copyright 2001-2011. All rights reserved.
SQL200 Resources Bookstore database scripts found on box.net at http://tinyurl.com/SQLScripts   Slides can be viewed on SlideShare… http://www.slideshare.net/OCDatabases   Follow up questions? [email_address]   Bookstore SQL212  Module 1
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
SQL/200 SQL Programming Part 1 – Modifying Data Bookstore SQL200 Module 3
Bookstore SQL200 Module 3 Relational Database with constraints (from text)
Data Modification Statements Insert Update Delete Bookstore SQL200 Module 3
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
Insert Adds new rows to an existing table Two forms: Single Row Multi-Row Bookstore SQL200 Module 3
Single Row Insert Bookstore SQL200 Module 3 Basic Syntax: Insert [into] <table-name> Values (<value-list>)
Single Row Insert Bookstore SQL200 Module 3 Basic Example: insert into  sources(source_numb, source_name, source_street) values (22,'Specialty Books', 'Canal Street')
Insert Statement Bookstore SQL200 Module 3
Sources table after Insert Bookstore SQL200 Module 3
Multi-row Insert Bookstore SQL200 Module 3 Basic Syntax: Insert [into] <table-name> Select <select-statement> We will do this after creating a new table later in this module
Update Updates fields in an existing row Bookstore SQL200 Module 3 Basic Syntax: Update <table-name> Set <field1> = new value, <field2> = new value,… Where <selection-criteria>
Update Increase Ingram prices by 10% Bookstore SQL200 Module 3 Example: Update books Set retail_price = retail_price *1.10 Where source_numb = 1
Ingram Book Prices before Update Bookstore SQL200 Module 3
Ingram Book Prices after Update Bookstore SQL200 Module 3
Bookstore SQL200 Module 3 After update in MS Access
Delete Deletes one or more rows Bookstore SQL200 Module 3 Basic Syntax: Delete from <table-name> Where <selection-criteria>
Delete Bookstore SQL200 Module 3 Example: Delete from sources Where source_numb = 22
Delete Bookstore SQL200 Module 3
Sources table after Delete Bookstore SQL200 Module 3
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
SQL/200 SQL Programming Part 2– Managing Database Structures Bookstore SQL200 Module 3
DDL Create Alter Drop Bookstore SQL200 Module 3
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
Tables Base tables Temporary tables  Local (or module scope) Global (session scope) Bookstore SQL200 Module 3
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
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
Create Table Bookstore SQL200 Module 3 Basic syntax: Create table <table-name> <column1> <datatype> <constraints> ,.. <column1> <datatype> <constraints> … <table constraints> Note: often preceded by a drop
Temporary Tables Bookstore SQL200 Module 3 Basic syntax (SQL standard): Create [global] temporary table <table-name> <rest of statement as for normal create> Note: SQL Server uses a different syntax. Just put a #in front of the table name as in #mytable.
Column Constraints Primary key Not NULL CHECK clause Default Unique Bookstore SQL200 Module 3
Table Constraints Primary Key Foreign Key Compare fields against each other. I.e. ship_date >= order_date Bookstore SQL200 Module 3
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
Create Table Bookstore SQL200 Module 3 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) )
Create Summary Table Bookstore SQL200 Module 3
Constraints on Summary Table Bookstore SQL200 Module 3
Multi-row Insert Bookstore SQL200 Module 3 Basic Syntax: Insert [into] <table-name> [(<column list>)] Select <select-statement>
Multi-row Insert Bookstore SQL200 Module 3 Basic Example:  (store # times each book ordered) Insert into summary Select isbn, count(*) From orderlines Group by isbn;
Multi-row Insert Bookstore SQL200 Module 3
Bookstore SQL200 Module 3 After multi-row insert in MS Access
SQL/200 SQL Programming Part 3 – Creating Views and Indexes, Modifying Structures Bookstore SQL200 Module 3
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
Views Bookstore SQL200 Module 3 Basic syntax: Create view <view-name> (<column-list>) As <select statement>
Creating a View Bookstore SQL200 Module 3
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
Using a View Bookstore SQL200 Module 3
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
Indexes Bookstore SQL200 Module 3 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
Indexes Bookstore SQL200 Module 3 Basic example: create index state_inx on customers(customer_state)
Customers table with index Bookstore SQL200 Module 3
Dropping an index Basic Syntax: Drop index <table-name.index-name>; Bookstore SQL200 Module 3
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
Modifying a Table Design Bookstore SQL200 Module 3 Basic syntax: Alter <table-name> Add <field-name>, Add <table-constraint>, Modify <field-name> Etc.
Modify a Table Design Bookstore SQL200 Module 3 Example: add a phone number field alter table publishers add phone char(12);
Bookstore SQL200 Module 3 After alter publishers table
SQL/200 SQL Programming Part 4 – Security Bookstore SQL200 Module 3
Security Important DBA function Beyond scope of this course Typically controlled through Enterprise Manager or Studio GUI’s In commercial practice application security frequently controlled via own login and a “users” table or similar Bookstore SQL200 Module 3
Security Specifics can vary by product Access: workgroup administrator SQL Server: users, roles Oracle: users, roles Bookstore SQL200 Module 3
SQL Security Statements Grant Revoke Deny Bookstore SQL200 Module 3
Grant Bookstore SQL200 Module 3 Syntax: Grant <access-right> [with grant option] On <object> to <user>   Note: by default only tables owners and admins can access a table. Others must be granted the relevant rights.
Access Rights Select Update Insert Delete References All privileges Bookstore SQL200 Module 3
Grant Bookstore SQL200 Module 3 Example: Grant update On employees to ddurso
Revoke Revokes the rights Syntax similar to grant Bookstore SQL200 Module 3 [end module]
Notes Bookstore SQL200 Module 3
Ad

More Related Content

What's hot (20)

Sql
SqlSql
Sql
Atul Pant
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
Belle Wx
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Getting Started with MySQL II
Getting Started with MySQL IIGetting Started with MySQL II
Getting Started with MySQL II
Sankhya_Analytics
 
Dbms practical list
Dbms practical listDbms practical list
Dbms practical list
RajSingh734307
 
Xml and databases
Xml and databasesXml and databases
Xml and databases
Raghu nath
 
Sq lite
Sq liteSq lite
Sq lite
Revuru Bharadwaja
 
SQL Views
SQL ViewsSQL Views
SQL Views
baabtra.com - No. 1 supplier of quality freshers
 
SQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate TableSQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate Table
1keydata
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
Swapnali Pawar
 
SQL Server Views
SQL Server ViewsSQL Server Views
SQL Server Views
Randy Riness @ South Puget Sound Community College
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
TechandMate
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
Farhan Aslam
 
MySQL lecture
MySQL lectureMySQL lecture
MySQL lecture
webhostingguy
 
06 qmds2005 session08
06 qmds2005 session0806 qmds2005 session08
06 qmds2005 session08
Niit Care
 
Sql basics
Sql  basicsSql  basics
Sql basics
Genesis Omo
 
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
Vibrant Technologies & Computers
 
ITCamp 2013 - Cristian Lefter - Transact-SQL from 0 to SQL Server 2012
ITCamp 2013 - Cristian Lefter - Transact-SQL from 0 to SQL Server 2012ITCamp 2013 - Cristian Lefter - Transact-SQL from 0 to SQL Server 2012
ITCamp 2013 - Cristian Lefter - Transact-SQL from 0 to SQL Server 2012
ITCamp
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
Tayyab Hussain
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
1keydata
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
Belle Wx
 
Getting Started with MySQL II
Getting Started with MySQL IIGetting Started with MySQL II
Getting Started with MySQL II
Sankhya_Analytics
 
Xml and databases
Xml and databasesXml and databases
Xml and databases
Raghu nath
 
SQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate TableSQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate Table
1keydata
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
TechandMate
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
Farhan Aslam
 
06 qmds2005 session08
06 qmds2005 session0806 qmds2005 session08
06 qmds2005 session08
Niit Care
 
ITCamp 2013 - Cristian Lefter - Transact-SQL from 0 to SQL Server 2012
ITCamp 2013 - Cristian Lefter - Transact-SQL from 0 to SQL Server 2012ITCamp 2013 - Cristian Lefter - Transact-SQL from 0 to SQL Server 2012
ITCamp 2013 - Cristian Lefter - Transact-SQL from 0 to SQL Server 2012
ITCamp
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
1keydata
 

Viewers also liked (20)

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
Dan D'Urso
 
SQL200.2 Module 2
SQL200.2 Module 2SQL200.2 Module 2
SQL200.2 Module 2
Dan D'Urso
 
Joins SQL Server
Joins SQL ServerJoins SQL Server
Joins SQL Server
baabtra.com - No. 1 supplier of quality freshers
 
MS SQL SERVER: Creating Views
MS SQL SERVER: Creating ViewsMS SQL SERVER: Creating Views
MS SQL SERVER: Creating Views
sqlserver content
 
Sql db optimization
Sql db optimizationSql db optimization
Sql db optimization
Nikhildas P C
 
Using grouping sets in sql server 2008 tech republic
Using grouping sets in sql server 2008   tech republicUsing grouping sets in sql server 2008   tech republic
Using grouping sets in sql server 2008 tech republic
Kaing Menglieng
 
Consultas en MS SQL Server 2012
Consultas en MS SQL Server 2012Consultas en MS SQL Server 2012
Consultas en MS SQL Server 2012
CarlosFloresRoman
 
Sql xp 04
Sql xp 04Sql xp 04
Sql xp 04
Niit Care
 
Sql tuning guideline
Sql tuning guidelineSql tuning guideline
Sql tuning guideline
Sidney Chen
 
Statistics
StatisticsStatistics
Statistics
Riteshkiit
 
Sub-queries,Groupby and having in SQL
Sub-queries,Groupby and having in SQLSub-queries,Groupby and having in SQL
Sub-queries,Groupby and having in SQL
Vikash Sharma
 
e computer notes - Subqueries
e computer notes - Subqueriese computer notes - Subqueries
e computer notes - Subqueries
ecomputernotes
 
Locking in SQL Server
Locking in SQL ServerLocking in SQL Server
Locking in SQL Server
Prashant Gogoi
 
Review of SQL
Review of SQLReview of SQL
Review of SQL
Information Technology
 
Triggers-Sequences-SQL
Triggers-Sequences-SQLTriggers-Sequences-SQL
Triggers-Sequences-SQL
Patrick Seery
 
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1 "Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
Andriy Krayniy
 
Lecture 4. MS SQL. DML Triggers
Lecture 4. MS SQL. DML TriggersLecture 4. MS SQL. DML Triggers
Lecture 4. MS SQL. DML Triggers
Alexey Furmanov
 
Sql query analyzer & maintenance
Sql query analyzer & maintenanceSql query analyzer & maintenance
Sql query analyzer & maintenance
nspyrenet
 
Locking And Concurrency
Locking And ConcurrencyLocking And Concurrency
Locking And Concurrency
sqlserver.co.il
 
SQL Server - Using Tools to Analyze Query Performance
SQL Server - Using Tools to Analyze Query PerformanceSQL Server - Using Tools to Analyze Query Performance
SQL Server - Using Tools to Analyze Query Performance
Marek Maśko
 
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
Dan D'Urso
 
SQL200.2 Module 2
SQL200.2 Module 2SQL200.2 Module 2
SQL200.2 Module 2
Dan D'Urso
 
MS SQL SERVER: Creating Views
MS SQL SERVER: Creating ViewsMS SQL SERVER: Creating Views
MS SQL SERVER: Creating Views
sqlserver content
 
Using grouping sets in sql server 2008 tech republic
Using grouping sets in sql server 2008   tech republicUsing grouping sets in sql server 2008   tech republic
Using grouping sets in sql server 2008 tech republic
Kaing Menglieng
 
Consultas en MS SQL Server 2012
Consultas en MS SQL Server 2012Consultas en MS SQL Server 2012
Consultas en MS SQL Server 2012
CarlosFloresRoman
 
Sql tuning guideline
Sql tuning guidelineSql tuning guideline
Sql tuning guideline
Sidney Chen
 
Sub-queries,Groupby and having in SQL
Sub-queries,Groupby and having in SQLSub-queries,Groupby and having in SQL
Sub-queries,Groupby and having in SQL
Vikash Sharma
 
e computer notes - Subqueries
e computer notes - Subqueriese computer notes - Subqueries
e computer notes - Subqueries
ecomputernotes
 
Triggers-Sequences-SQL
Triggers-Sequences-SQLTriggers-Sequences-SQL
Triggers-Sequences-SQL
Patrick Seery
 
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1 "Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
Andriy Krayniy
 
Lecture 4. MS SQL. DML Triggers
Lecture 4. MS SQL. DML TriggersLecture 4. MS SQL. DML Triggers
Lecture 4. MS SQL. DML Triggers
Alexey Furmanov
 
Sql query analyzer & maintenance
Sql query analyzer & maintenanceSql query analyzer & maintenance
Sql query analyzer & maintenance
nspyrenet
 
SQL Server - Using Tools to Analyze Query Performance
SQL Server - Using Tools to Analyze Query PerformanceSQL Server - Using Tools to Analyze Query Performance
SQL Server - Using Tools to Analyze Query Performance
Marek Maśko
 
Ad

Similar to SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3 (20)

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
Dan D'Urso
 
SQL commands in database managemant systems
SQL commands in database managemant systemsSQL commands in database managemant systems
SQL commands in database managemant systems
pmselvaraj
 
introduction to SQL query language beginner.ppt
introduction to SQL query language beginner.pptintroduction to SQL query language beginner.ppt
introduction to SQL query language beginner.ppt
PatriceRochon1
 
SQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxSQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptx
KashifManzoorMeo
 
SQL302 Intermediate SQL Workshop 3
SQL302 Intermediate SQL Workshop 3SQL302 Intermediate SQL Workshop 3
SQL302 Intermediate SQL Workshop 3
Dan D'Urso
 
SQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxSQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptx
QuyVo27
 
DBMS LAB FILE1 task 1 , task 2, task3 and many more.pdf
DBMS LAB FILE1 task 1 , task 2, task3 and many more.pdfDBMS LAB FILE1 task 1 , task 2, task3 and many more.pdf
DBMS LAB FILE1 task 1 , task 2, task3 and many more.pdf
AbhishekKumarPandit5
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro project
ARVIND SARDAR
 
DBMS week 2 hjghg hvgfhgf,3 BSCS 6th.pptx
DBMS week 2 hjghg hvgfhgf,3 BSCS 6th.pptxDBMS week 2 hjghg hvgfhgf,3 BSCS 6th.pptx
DBMS week 2 hjghg hvgfhgf,3 BSCS 6th.pptx
universalcomputer1
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
NIRMAL FELIX
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
metsarin
 
DBMSLab_SQL_4thsem_CI_17163544545446962.pptx
DBMSLab_SQL_4thsem_CI_17163544545446962.pptxDBMSLab_SQL_4thsem_CI_17163544545446962.pptx
DBMSLab_SQL_4thsem_CI_17163544545446962.pptx
dgfs55437
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptx
SiddhantBhardwaj26
 
Module 3
Module 3Module 3
Module 3
cs19club
 
SQL200A Microsoft Access SQL Design
SQL200A Microsoft Access SQL DesignSQL200A Microsoft Access SQL Design
SQL200A Microsoft Access SQL Design
Dan D'Urso
 
mysqlHiep.ppt
mysqlHiep.pptmysqlHiep.ppt
mysqlHiep.ppt
webhostingguy
 
MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinh
webhostingguy
 
Sql views, stored procedure, functions
Sql views, stored procedure, functionsSql views, stored procedure, functions
Sql views, stored procedure, functions
Om Vikram Thapa
 
Introduction to Threading in .Net
Introduction to Threading in .NetIntroduction to Threading in .Net
Introduction to Threading in .Net
webhostingguy
 
Android sq lite-chapter 22
Android sq lite-chapter 22Android sq lite-chapter 22
Android sq lite-chapter 22
Dr. Ramkumar Lakshminarayanan
 
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
Dan D'Urso
 
SQL commands in database managemant systems
SQL commands in database managemant systemsSQL commands in database managemant systems
SQL commands in database managemant systems
pmselvaraj
 
introduction to SQL query language beginner.ppt
introduction to SQL query language beginner.pptintroduction to SQL query language beginner.ppt
introduction to SQL query language beginner.ppt
PatriceRochon1
 
SQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxSQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptx
KashifManzoorMeo
 
SQL302 Intermediate SQL Workshop 3
SQL302 Intermediate SQL Workshop 3SQL302 Intermediate SQL Workshop 3
SQL302 Intermediate SQL Workshop 3
Dan D'Urso
 
SQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxSQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptx
QuyVo27
 
DBMS LAB FILE1 task 1 , task 2, task3 and many more.pdf
DBMS LAB FILE1 task 1 , task 2, task3 and many more.pdfDBMS LAB FILE1 task 1 , task 2, task3 and many more.pdf
DBMS LAB FILE1 task 1 , task 2, task3 and many more.pdf
AbhishekKumarPandit5
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro project
ARVIND SARDAR
 
DBMS week 2 hjghg hvgfhgf,3 BSCS 6th.pptx
DBMS week 2 hjghg hvgfhgf,3 BSCS 6th.pptxDBMS week 2 hjghg hvgfhgf,3 BSCS 6th.pptx
DBMS week 2 hjghg hvgfhgf,3 BSCS 6th.pptx
universalcomputer1
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
NIRMAL FELIX
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
metsarin
 
DBMSLab_SQL_4thsem_CI_17163544545446962.pptx
DBMSLab_SQL_4thsem_CI_17163544545446962.pptxDBMSLab_SQL_4thsem_CI_17163544545446962.pptx
DBMSLab_SQL_4thsem_CI_17163544545446962.pptx
dgfs55437
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptx
SiddhantBhardwaj26
 
SQL200A Microsoft Access SQL Design
SQL200A Microsoft Access SQL DesignSQL200A Microsoft Access SQL Design
SQL200A Microsoft Access SQL Design
Dan D'Urso
 
MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinh
webhostingguy
 
Sql views, stored procedure, functions
Sql views, stored procedure, functionsSql views, stored procedure, functions
Sql views, stored procedure, functions
Om Vikram Thapa
 
Introduction to Threading in .Net
Introduction to Threading in .NetIntroduction to Threading in .Net
Introduction to Threading in .Net
webhostingguy
 
Ad

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
Dan D'Urso
 
LCD201d Database Diagramming with Lucidchart
LCD201d Database Diagramming with LucidchartLCD201d Database Diagramming with Lucidchart
LCD201d Database Diagramming with Lucidchart
Dan D'Urso
 
Database Normalization
Database NormalizationDatabase Normalization
Database Normalization
Dan D'Urso
 
VIS201d Visio Database Diagramming
VIS201d Visio Database DiagrammingVIS201d Visio Database Diagramming
VIS201d Visio Database Diagramming
Dan D'Urso
 
PRJ101a Project 2013 Accelerated
PRJ101a Project 2013 AcceleratedPRJ101a Project 2013 Accelerated
PRJ101a Project 2013 Accelerated
Dan D'Urso
 
PRJ101xl Project Libre Basic Training
PRJ101xl Project Libre Basic TrainingPRJ101xl Project Libre Basic Training
PRJ101xl Project Libre Basic Training
Dan D'Urso
 
Introduction to coding using Python
Introduction to coding using PythonIntroduction to coding using Python
Introduction to coding using Python
Dan D'Urso
 
Stem conference
Stem conferenceStem conference
Stem conference
Dan D'Urso
 
Microsoft access self joins
Microsoft access self joinsMicrosoft access self joins
Microsoft access self joins
Dan D'Urso
 
SQL302 Intermediate SQL
SQL302 Intermediate SQLSQL302 Intermediate SQL
SQL302 Intermediate SQL
Dan D'Urso
 
AIN106 Access Reporting and Analysis
AIN106 Access Reporting and AnalysisAIN106 Access Reporting and Analysis
AIN106 Access Reporting and Analysis
Dan D'Urso
 
SQL302 Intermediate SQL Workshop 2
SQL302 Intermediate SQL Workshop 2SQL302 Intermediate SQL Workshop 2
SQL302 Intermediate SQL Workshop 2
Dan D'Urso
 
Course Catalog
Course CatalogCourse Catalog
Course Catalog
Dan D'Urso
 
SQL302 Intermediate SQL Workshop 1
SQL302 Intermediate SQL Workshop 1SQL302 Intermediate SQL Workshop 1
SQL302 Intermediate SQL Workshop 1
Dan D'Urso
 
SQL212 Oracle SQL Manual
SQL212 Oracle SQL ManualSQL212 Oracle SQL Manual
SQL212 Oracle SQL Manual
Dan D'Urso
 
SQL201W MySQL SQL Manual
SQL201W MySQL SQL ManualSQL201W MySQL SQL Manual
SQL201W MySQL SQL Manual
Dan D'Urso
 
AIN100
AIN100AIN100
AIN100
Dan D'Urso
 
SQL206 SQL Median
SQL206 SQL MedianSQL206 SQL Median
SQL206 SQL Median
Dan D'Urso
 
SQL202 SQL Server SQL Manual
SQL202 SQL Server SQL ManualSQL202 SQL Server SQL Manual
SQL202 SQL Server SQL Manual
Dan D'Urso
 
AIN102 Microsoft Access Queries
AIN102 Microsoft Access QueriesAIN102 Microsoft Access Queries
AIN102 Microsoft Access Queries
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 Queries
Dan D'Urso
 
LCD201d Database Diagramming with Lucidchart
LCD201d Database Diagramming with LucidchartLCD201d Database Diagramming with Lucidchart
LCD201d Database Diagramming with Lucidchart
Dan D'Urso
 
Database Normalization
Database NormalizationDatabase Normalization
Database Normalization
Dan D'Urso
 
VIS201d Visio Database Diagramming
VIS201d Visio Database DiagrammingVIS201d Visio Database Diagramming
VIS201d Visio Database Diagramming
Dan D'Urso
 
PRJ101a Project 2013 Accelerated
PRJ101a Project 2013 AcceleratedPRJ101a Project 2013 Accelerated
PRJ101a Project 2013 Accelerated
Dan D'Urso
 
PRJ101xl Project Libre Basic Training
PRJ101xl Project Libre Basic TrainingPRJ101xl Project Libre Basic Training
PRJ101xl Project Libre Basic Training
Dan D'Urso
 
Introduction to coding using Python
Introduction to coding using PythonIntroduction to coding using Python
Introduction to coding using Python
Dan D'Urso
 
Stem conference
Stem conferenceStem conference
Stem conference
Dan D'Urso
 
Microsoft access self joins
Microsoft access self joinsMicrosoft access self joins
Microsoft access self joins
Dan D'Urso
 
SQL302 Intermediate SQL
SQL302 Intermediate SQLSQL302 Intermediate SQL
SQL302 Intermediate SQL
Dan D'Urso
 
AIN106 Access Reporting and Analysis
AIN106 Access Reporting and AnalysisAIN106 Access Reporting and Analysis
AIN106 Access Reporting and Analysis
Dan D'Urso
 
SQL302 Intermediate SQL Workshop 2
SQL302 Intermediate SQL Workshop 2SQL302 Intermediate SQL Workshop 2
SQL302 Intermediate SQL Workshop 2
Dan D'Urso
 
Course Catalog
Course CatalogCourse Catalog
Course Catalog
Dan D'Urso
 
SQL302 Intermediate SQL Workshop 1
SQL302 Intermediate SQL Workshop 1SQL302 Intermediate SQL Workshop 1
SQL302 Intermediate SQL Workshop 1
Dan D'Urso
 
SQL212 Oracle SQL Manual
SQL212 Oracle SQL ManualSQL212 Oracle SQL Manual
SQL212 Oracle SQL Manual
Dan D'Urso
 
SQL201W MySQL SQL Manual
SQL201W MySQL SQL ManualSQL201W MySQL SQL Manual
SQL201W MySQL SQL Manual
Dan D'Urso
 
SQL206 SQL Median
SQL206 SQL MedianSQL206 SQL Median
SQL206 SQL Median
Dan D'Urso
 
SQL202 SQL Server SQL Manual
SQL202 SQL Server SQL ManualSQL202 SQL Server SQL Manual
SQL202 SQL Server SQL Manual
Dan D'Urso
 
AIN102 Microsoft Access Queries
AIN102 Microsoft Access QueriesAIN102 Microsoft Access Queries
AIN102 Microsoft Access Queries
Dan D'Urso
 

Recently uploaded (20)

Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 

SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3

  • 1. SQL/200 SQL Programming Workshop 3 – Modifying Data, Managing the Database Bookstore SQL200 Module 3 Based on SQL Clearly Explained by Jan Harrington
  • 2. Note on SQL200 Slides These slides were originally designed to support the single SQL200 course which was used for any of MS Access, Oracle and SQL Server. As such you may see here slides developed in any one of the above products. We are in the process of migrating the Oracle slides and the MS Access slides out into their own slide sets. These SQL200 slides (used in SQL202 as well as SQL200) will focus on Microsoft SQL Server. Bookstore SQL200 Module 3
  • 3. Warning! Below are some table name changes to be aware of in doing queries. We have created synonyms so either name should work. Bookstore2 SQL200 Module 2 New Name Old Name Orders Order_filled Order_Lines Orderlines
  • 4. SQL200 Contact Information Bookstore SQL200 Module 3 P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 http://www.d2associates.com [email_address] Copyright 2001-2011. All rights reserved.
  • 5. SQL200 Resources Bookstore database scripts found on box.net at http://tinyurl.com/SQLScripts Slides can be viewed on SlideShare… http://www.slideshare.net/OCDatabases Follow up questions? [email_address] Bookstore SQL212 Module 1
  • 6. 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
  • 7. SQL/200 SQL Programming Part 1 – Modifying Data Bookstore SQL200 Module 3
  • 8. Bookstore SQL200 Module 3 Relational Database with constraints (from text)
  • 9. Data Modification Statements Insert Update Delete Bookstore SQL200 Module 3
  • 10. 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
  • 11. Insert Adds new rows to an existing table Two forms: Single Row Multi-Row Bookstore SQL200 Module 3
  • 12. Single Row Insert Bookstore SQL200 Module 3 Basic Syntax: Insert [into] <table-name> Values (<value-list>)
  • 13. Single Row Insert Bookstore SQL200 Module 3 Basic Example: insert into sources(source_numb, source_name, source_street) values (22,'Specialty Books', 'Canal Street')
  • 14. Insert Statement Bookstore SQL200 Module 3
  • 15. Sources table after Insert Bookstore SQL200 Module 3
  • 16. Multi-row Insert Bookstore SQL200 Module 3 Basic Syntax: Insert [into] <table-name> Select <select-statement> We will do this after creating a new table later in this module
  • 17. Update Updates fields in an existing row Bookstore SQL200 Module 3 Basic Syntax: Update <table-name> Set <field1> = new value, <field2> = new value,… Where <selection-criteria>
  • 18. Update Increase Ingram prices by 10% Bookstore SQL200 Module 3 Example: Update books Set retail_price = retail_price *1.10 Where source_numb = 1
  • 19. Ingram Book Prices before Update Bookstore SQL200 Module 3
  • 20. Ingram Book Prices after Update Bookstore SQL200 Module 3
  • 21. Bookstore SQL200 Module 3 After update in MS Access
  • 22. Delete Deletes one or more rows Bookstore SQL200 Module 3 Basic Syntax: Delete from <table-name> Where <selection-criteria>
  • 23. Delete Bookstore SQL200 Module 3 Example: Delete from sources Where source_numb = 22
  • 25. Sources table after Delete Bookstore SQL200 Module 3
  • 26. 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
  • 27. SQL/200 SQL Programming Part 2– Managing Database Structures Bookstore SQL200 Module 3
  • 28. DDL Create Alter Drop Bookstore SQL200 Module 3
  • 29. 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
  • 30. Tables Base tables Temporary tables Local (or module scope) Global (session scope) Bookstore SQL200 Module 3
  • 31. 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
  • 32. 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
  • 33. Create Table Bookstore SQL200 Module 3 Basic syntax: Create table <table-name> <column1> <datatype> <constraints> ,.. <column1> <datatype> <constraints> … <table constraints> Note: often preceded by a drop
  • 34. Temporary Tables Bookstore SQL200 Module 3 Basic syntax (SQL standard): Create [global] temporary table <table-name> <rest of statement as for normal create> Note: SQL Server uses a different syntax. Just put a #in front of the table name as in #mytable.
  • 35. Column Constraints Primary key Not NULL CHECK clause Default Unique Bookstore SQL200 Module 3
  • 36. Table Constraints Primary Key Foreign Key Compare fields against each other. I.e. ship_date >= order_date Bookstore SQL200 Module 3
  • 37. 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
  • 38. Create Table Bookstore SQL200 Module 3 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) )
  • 39. Create Summary Table Bookstore SQL200 Module 3
  • 40. Constraints on Summary Table Bookstore SQL200 Module 3
  • 41. Multi-row Insert Bookstore SQL200 Module 3 Basic Syntax: Insert [into] <table-name> [(<column list>)] Select <select-statement>
  • 42. Multi-row Insert Bookstore SQL200 Module 3 Basic Example: (store # times each book ordered) Insert into summary Select isbn, count(*) From orderlines Group by isbn;
  • 43. Multi-row Insert Bookstore SQL200 Module 3
  • 44. Bookstore SQL200 Module 3 After multi-row insert in MS Access
  • 45. SQL/200 SQL Programming Part 3 – Creating Views and Indexes, Modifying Structures Bookstore SQL200 Module 3
  • 46. 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
  • 47. Views Bookstore SQL200 Module 3 Basic syntax: Create view <view-name> (<column-list>) As <select statement>
  • 48. Creating a View Bookstore SQL200 Module 3
  • 49. 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
  • 50. Using a View Bookstore SQL200 Module 3
  • 51. 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
  • 52. Indexes Bookstore SQL200 Module 3 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
  • 53. Indexes Bookstore SQL200 Module 3 Basic example: create index state_inx on customers(customer_state)
  • 54. Customers table with index Bookstore SQL200 Module 3
  • 55. Dropping an index Basic Syntax: Drop index <table-name.index-name>; Bookstore SQL200 Module 3
  • 56. 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
  • 57. Modifying a Table Design Bookstore SQL200 Module 3 Basic syntax: Alter <table-name> Add <field-name>, Add <table-constraint>, Modify <field-name> Etc.
  • 58. Modify a Table Design Bookstore SQL200 Module 3 Example: add a phone number field alter table publishers add phone char(12);
  • 59. Bookstore SQL200 Module 3 After alter publishers table
  • 60. SQL/200 SQL Programming Part 4 – Security Bookstore SQL200 Module 3
  • 61. Security Important DBA function Beyond scope of this course Typically controlled through Enterprise Manager or Studio GUI’s In commercial practice application security frequently controlled via own login and a “users” table or similar Bookstore SQL200 Module 3
  • 62. Security Specifics can vary by product Access: workgroup administrator SQL Server: users, roles Oracle: users, roles Bookstore SQL200 Module 3
  • 63. SQL Security Statements Grant Revoke Deny Bookstore SQL200 Module 3
  • 64. Grant Bookstore SQL200 Module 3 Syntax: Grant <access-right> [with grant option] On <object> to <user> Note: by default only tables owners and admins can access a table. Others must be granted the relevant rights.
  • 65. Access Rights Select Update Insert Delete References All privileges Bookstore SQL200 Module 3
  • 66. Grant Bookstore SQL200 Module 3 Example: Grant update On employees to ddurso
  • 67. Revoke Revokes the rights Syntax similar to grant Bookstore SQL200 Module 3 [end module]