Download presentation
Presentation is loading. Please wait.
1
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 COS 346 Day 11
2
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-2 Agenda Questions? Assignment 4 Due Feb 23 Capstone Project Proposal Due Feb 27 –Must be a database project Quiz 1 –Feb 23 –DP Chap 1-6, SQL Chap 1 & 2 –20 M/C and 5 Short Essay –70 mins –Password “EFCodd” Lecture Starts at 4:50PM Sharp SQL for Database Construction and Application Processing
3
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-3 David M. Kroenke’s Chapter Seven: SQL for Database Construction and Application Processing Part One Database Processing: Fundamentals, Design, and Implementation
4
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-4 View Ridge Gallery View Ridge Gallery is a small art gallery that has been in business for 30 years. It sells contemporary European and North American fine art. View Ridge has one owner, three salespeople, and two workers. View Ridge owns all of the art that it sells; it holds no items on a consignment basis.
5
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-5 Application Requirements View Ridge application requirements: –Track customers and their artist interests –Record gallery's purchases –Record customers' art purchases –List the artists and works that have appeared in the gallery –Report how fast an artist's works have sold and at what margin –Show current inventory in a Web page
6
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-6 View Ridge Gallery Database Design
7
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-7 SQL DDL and DML
8
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-8 The Database Design for ARTIST and WORK
9
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-9 CREATE TABLE CREATE TABLE statement is used for creating relations Each column is described with three parts: column name, data type, and optional constraints Example:
10
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-10 Data Types
11
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-11 Constraints Constraints can be defined within the CREATE TABLE statement, or they can be added to the table after it is created using the ALTER table statement Five types of constraints: –PRIMARY KEY may not have null values –UNIQUE may have null values –NULL/NOT NULL –FOREIGN KEY –CHECK
12
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-12 Creating Relationships
13
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-13 Implementing Cardinalities
14
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-14 Default Values and Data Constraints
15
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-15 SQL for Constraints
16
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-16 ALTER Statement ALTER statement changes table structure, properties, or constraints after it has been created Example: ALTER TABLE ASSIGNMENT ADD CONSTRAINT EmployeeFK FOREIGN KEY (EmployeeNum) REFERENCES EMPLOYEE (EmployeeNumber) ON UPDATE CASCADE ON DELETE NO ACTION;
17
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-17 Adding and Dropping Columns The following statement will add a column named MyColumn to the CUSTOMER table: ALTER TABLE CUSTOMER ADD MyColumn Char(5) NULL; You can drop an existing column with the statement: ALTER TABLE CUSTOMER DROP COLUMN MyColumn ;
18
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-18 Adding and Dropping Constraints ALTER can be used to add a constraint as follows: ALTER TABLE CUSTOMER ADD CONSTRAINT MyConstraint CHECK ([Name] NOT IN ('Robert No Pay')); ALTER can be used to drop a constraint: ALTER TABLE CUSTOMER DROP CONSTRAINT MyConstraint;
19
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-19 Removing Tables SQL DROP TABLE: DROP TABLE [TRANSACTION]; If there are constraints : ALTER TABLE CUSTOMER_ARTIST_INT DROP CONSTRAINT Customer_Artist_Int_CustomerFK; ALTER TABLE [TRANSACTION] DROP CONSTRAINT TransactionCustomerFK; DROP TABLE CUSTOMER;
20
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-20 SQL DML - INSERT INSERT command: INSERT INTO ARTIST ([Name], Nationality, Birthdate, DeceasedDate) VALUES ('Tamayo', 'Mexican', 1927, 1998); Bulk INSERT: INSERT INTO ARTIST ([Name], Nationality, Birthdate) SELECT [Name], Nationality, Birthdate FROM IMPORTED_ARTIST;
21
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-21 David M. Kroenke’s Database Processing Fundamentals, Design, and Implementation (10 th Edition) End of Presentation: Chapter Seven Part One
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.