CREATE TABLE ARTIST ( ArtistID int NOT NULL IDENTITY (1,1), Namechar(25) NOT NULL, TEXT ERROR Nationality char (30) NULL, Birthdate numeric (4,0) NULL,

Slides:



Advertisements
Similar presentations
Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.
Advertisements

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-1 David M. Kroenke’s Chapter Eight: Database Redesign Database Processing:
Fundamentals, Design, and Implementation, 9/e Chapter 8 Database Redesign.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-1 David M. Kroenke’s Chapter Eight: Database Redesign Database Processing:
Maintaining Referential Integrity Pertemuan 2 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
Constraints We have discussed three types of integrity constraints: primary keys, not null constraints, and unique constraints. CREATE TABLE Movies ( title.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 COS 346 Day 11.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 COS 346 Day 12.
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
Creating Tables, Defining Constraints Rose-Hulman Institute of Technology Curt Clifton.
SQL Keys and Constraints Justin Maksim. Key Declaration Key constraint defined within the CREATE TABLE command Key can be declared using either the PRIMARY.
Student(sid, name, addr, age, GPA) Class(dept, cnum, sec, unit, title, instructor) Enroll(sid, dept, cnum, sec) siddeptcnumsec 301CS CS AT00000.
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 10: Data Definition Language.
Slide 1 Chapter 7 – Part 2 Chapter 7 – Part 2 Constraints JOIN statement View.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
SQL Data Definition (CB Chapter 6) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
Slide 1 Chapter 7 – Part 1 Data Definition Language & Data Manipulation Language.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
ICS 321 Fall 2011 Constraints, Triggers, Views & Indexes Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Recap of SQL Lab no 8 Advance Database Management System.
Intro to SQL| MIS 2502  Spacing not relevant › BUT… no spaces in an attribute name or table name  Oracle commands keywords, table names, and attribute.
CN2180 MS SQL Server Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP.
Creating Tables and Inserting Records -- Not easy to edit! -- check constraints! Create table test1 ( C1 char(5) primary key, C2 Varchar2(15) not null.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
CS 3630 Database Design and Implementation. Database Schema Branch (Bno…) Staff (Sno…Bno) Owner (Ono…) PropertyForRent (Pno…Ono) Renter (Rno…) Viewing.
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
1 SQL - II Data Constraints –Applying data constraints Types of data constraints –I/O constraints The PRIMARY KEY constraints The FOREIGN KEY constraints.
Chapter 9 Constraints. Chapter Objectives  Explain the purpose of constraints in a table  Distinguish among PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK,
Oracle 11g: SQL Chapter 4 Constraints.
Introduction to Database System Adisak Intana Lecturer Chapter 7 : Data Integrity.
SQL for Database Construction and Application Processing
CREATE TABLE CREATE TABLE statement is used for creating relations Each column is described with three parts: column name, data type, and optional constraints.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/1 Copyright © 2004 Please……. No Food Or Drink in the class.
SQL introduction 2013.
Fundamentals, Design, and Implementation, 9/e Chapter 8 Database Redesign.
13 Copyright © Oracle Corporation, All rights reserved. Maintaining Data Integrity.
Managing Database With Oracle Replacement for Ch10 COP 4708.
* Database is a group of related objects * Objects can be Tables, Forms, Queries or Reports * All data reside in Tables * A Row in a Table is a record.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
SQL constrains and keys. SORTED RESULTS Sort the results by a specified criterion SELECT columns FROM tables WHERE predicates ORDER BY column ASC/DESC;
UNIVERSITAS BINA DARMA 2013 DATA DEFINITION LANGUAGE (DDL)
Command-line Oracle Logon to your ORACLE account using the instructions contained in this slideshow. Create the tables with your last name in place of.
Murali Mani Constraints. Murali Mani Keys: Primary keys and unique CREATE TABLE Student ( sNum int, sName varchar (20), dept char (2), CONSTRAINT key.
MS SQL Create Table Cust USE jxc00 GO CREATE TABLE cust ( cust_id smallint IDENTITY(1,1) NOT NULL, cust_name char(10)
SQL – More Table Constraints
Referential Integrity MySQL
Module 5: Implementing Data Integrity by Using Constraints
Ch7. SQL for DB construction and Application Processing 데이터베이스시스템 (ND352) 교수 홍 기 형.
Lecturer: Mukhtar Mohamed Ali “Hakaale”
For student, require values for name and address.
DATABASE SQL= Structure Query Language مبادئ قواعد بيانات
CS122 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
Database Processing: David M. Kroenke’s Chapter Seven:
Session - 6 Sequence - 1 SQL: The Structured Query Language:
CS1222 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
Instructor: Samia arshad
CS122 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
កម្មវិធីបង្រៀន SQL Programming ជាភាសាខ្មែរ Online SQL Training Course
SQL NOT NULL Constraint
SQL (Structured Query Language)
Presentation transcript:

CREATE TABLE ARTIST ( ArtistID int NOT NULL IDENTITY (1,1), Namechar(25) NOT NULL, TEXT ERROR Nationality char (30) NULL, Birthdate numeric (4,0) NULL, DeceasedDate numeric (4,0)NULL, CONSTRAINT ArtistPK PRIMARY KEY (ArtistID) CONSTRAINT ArtistAK UNIQUE (Name) );

CREATE TABLE ARTIST ( ArtistID int NOT NULL IDENTITY (1,1), Namechar(25) NOT NULL, Nationality char (30) NULL, Birthdate numeric (4,0) NULL, DeceasedDate numeric (4,0) NULL CONSTRAINT ArtistPK PRIMARY KEY (ArtistID) CONSTRAINT ArtistAK UNIQUE (Name) ); Also erroneous – see following slide

Result of running CREATE TABLE ARTIST

Altered CREATE statement CREATE TABLE ARTIST ( ArtistID int NOT NULL IDENTITY (1,1) CONSTRAINT ArtistPK PRIMARY KEY (ArtistID), Namechar(25) NOT NULL CONSTRAINT ArtistAK UNIQUE (Name), Nationality char (30) NULL, Birthdate numeric (4,0) NULL, DeceasedDate numeric (4,0)NULL );

CREATE TABLE example CREATE TABLE MYARTIST ( ArtistID int NOT NULL IDENTITY (1,1) CONSTRAINT ArtistPK PRIMARY KEY (ArtistID), Aname char(25) NOT NULL CONSTRAINT ArtistAK UNIQUE (Aname), Birthdate numeric(4,0) NULL, DeceasedDate numeric (4,0) NULL );

Created to show effect of NO ACTION CREATE TABLE WORK ( WorkID int NOT NULL IDENTITY (500,1), Titlechar(25) NOT NULL, Copy char(8) NOT NULL, Description varchar (1000) NULL, ArtistID int NOT NULL CONSTRAINT WorkPK PRIMARY KEY(WorkID), CONSTRAINT WorkAK1 UNIQUE (Title, Copy), CONSTRAINT ArtistFK FOREIGN KEY (ArtistID) REFERENCES ARTIST (ArtistID) ON DELETE NO ACTION ON UPDATE NO ACTION We were NOT able to delete a row in ARTIST whose Artist ID was referenced by WORK

Created to show effect of CASCADE CREATE TABLE SOMEWORK ( WorkID int NOT NULL IDENTITY (500,1), Titlechar(25) NOT NULL, Copy char(8) NOT NULL, Description varchar (1000) NULL, ArtistID int NOT NULL CONSTRAINT WorkPK3 PRIMARY KEY(WorkID), CONSTRAINT WorkAK3 UNIQUE (Title, Copy), CONSTRAINT ArtistFK3 FOREIGN KEY (ArtistID) REFERENCES MYARTIST (ArtistID) ON DELETE CASCADE ON UPDATE CASCADE ); We were able to delete a row in MYARTIST whose Artist ID was referenced by SOMEWORK and the referencing rows in SOMEWORK were also deleted.

ALTER dropped column with no data in it ALTER TABLE MYARTIST DROP COLUMN DeceasedDate;

ALTER dropped column with data in it ALTER TABLE ARTIST DROP COLUMN DeceasedDate;