Agenda for Class 2/02/2006 Finish discussing constraints generated with the CREATE TABLE statement. Discuss DROP statement. Discuss INSERT, COMMIT, DELETE,

Slides:



Advertisements
Similar presentations
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
Advertisements

Agenda for Class 2/16/2012 Introduce Microsoft’s SQL Server database management system. Use the lab to discuss how to CREATE, DROP and populate (INSERT)
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
Introduction to Structured Query Language (SQL)
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
5 Chapter 5 Structured Query Language (SQL1) Revision.
Introduction to Structured Query Language (SQL)
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-1 David M. Kroenke Database Processing Chapter 7 Structured Query Language.
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
Oracle Data Definition Language (DDL)
Introduction to DBMS and SQL Introduction to DBMS and SQL GUIDED BY : MR. YOGESH SAROJ (PGT-CS) MR. YOGESH SAROJ (PGT-CS) Presented By : JAYA XII –COM.
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
Working with Tables: Data Management and Retrieval Dr. Bernard Chen Ph.D. University of Central Arkansas.
Database Design lecture 3_1 1 Database Design Lecture 3_1 Data definition in SQL.
SQL Data Definition (CB Chapter 6) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
Fundamentals, Design, and Implementation, 9/e CPE 481 Database Processing Chapter 6 Structured Query Language (SQL) Instructor:Suthep Madarasmi, Ph.D.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
1 Creating and Modifying Database Objects. 2 An Oracle database consists of multiple user accounts Each user account owns database objects Tables Views.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
CS 3630 Database Design and Implementation. Assignment 3 Style! Agreement between database designer and the client. UserName1_EasyDrive UserName2_EasyDrive.
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.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
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.
© 2002 by Prentice Hall 1 Database Processing with Microsoft Access David M. Kroenke Database Concepts 1e Appendix A.
Agenda for Class 9/25/2012 Introduce Microsoft’s SQL Server database management system. Use the lab to discuss how to CREATE, DROP and populate (INSERT)
Creating Tables and Inserting Records -- Not easy to edit! -- check constraints! Create table test1 ( C1 char(5) primary key, C2 Varchar2(15) not null.
Database Processing with Microsoft Access Appendix DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
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.
Constraints cis 407 Types of Constraints & Naming Key Constraints Unique Constraints Check Constraints Default Constraints Misc Rules and Defaults Triggers.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
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.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
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.
Objectives Database triggers and syntax
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
1 SQL-2 Tarek El-Shishtawy Professor Ass. Of Computer Engineering.
1 DBS201: More on SQL Lecture 3. 2 Agenda How to use SQL to update table definitions How to update data in a table How to join tables together.
IS 380 Introduction to SQL This lectures covers material from: database textbook chapter 3 Oracle chapter: 3,14,17.
1 Chapter 2: Creating and Modifying Database Objects.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
Agenda for Class 2/20/2014 Introduce Microsoft’s SQL Server database management system. Use the lab to discuss how to CREATE, DROP and populate (INSERT)
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
Further Consolidation Objectives of the Lecture : To use simple queries to check out a DB. To use insertions, deletions and amendments to maintain a DB.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
Basic SQL*Plus edit and execute commands SQL*Plus buffer and built-in editor holds the last SQL statement Statements are created in free-flow style and.
1 DBS201: More on SQL Lecture 2. 2 Agenda Select command review How to create a table How to insert data into a table.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
Oracle sql Online Training By SMART MIND ONLINE TRAINING Website:
2 Copyright © 2009, Oracle. All rights reserved. Managing Schema Objects.
Database Constraints ICT 011. Database Constraints Database constraints are restrictions on the contents of the database or on database operations Database.
CS 3630 Database Design and Implementation
Oracle Data Definition Language (DDL)
Database Management System
Presentation transcript:

Agenda for Class 2/02/2006 Finish discussing constraints generated with the CREATE TABLE statement. Discuss DROP statement. Discuss INSERT, COMMIT, DELETE, and UPDATE statements. Introduce SELECT statement. Discuss a few helpful SQLPlus commands. Do SQL class exercise.

Example 1: Simple Order Database discussed in class on Tuesday: We discussed in class how to create the tables with primary key and referential integrity constraints, now let’s add some other constraints.

CREATE TABLE ord (order_no NUMBER(5), order_date DATE, customer_no NUMBER(3) NOT NULL, ship_code CHAR(2) CHECK (ship_code in(‘02’,’A1’,’B3’,’04’)), CONSTRAINT ord_pk PRIMARY KEY (order_no)); CREATE TABLE prod (prod_no NUMBER(3), description VARCHAR2(50), cost NUMBER(8,2)CHECK (cost >.02), CONSTRAINT prod_pk PRIMARY KEY (prod_no)); CREATE TABLE prod_on_ord (order_no NUMBER(5), prod_no NUMBER(3), quantity NUMBER(6,2)DEFAULT 1, price NUMBER(8,2), CONSTRAINT prodord_pk PRIMARY KEY (order_no, prod_no), CONSTRAINT ord_fk FOREIGN KEY(order_no) REFERENCES ord(order_no), CONSTRAINT prod_fk FOREIGN KEY(prod_no) REFERENCES prod(prod_no));

What is a recursive referential integrity constraint? Imagine a situation where a company is a parent company of another company. The organization as a whole keeps track of company name, phone and the identifier of the parent company. CompanyIDNamePhoneParentCompanyID 123Dining Supply Co null 177DineOut RestCo Jansen Supply

Creating a recursive referential integrity constraint CREATE TABLE company (companyIDCHAR(3), companynameVARCHAR2(40), phoneCHAR(10), parentcompanyIDCHAR(3), CONSTRAINT company_pk PRIMARY KEY (companyID), CONSTRAINT parent_fk FOREIGN KEY (parentcompanyID) REFERENCES company(companyID));

Deleting a table Cannot have more than one data object with the same name. Must delete data objects before re-creating them. SQL Statement is: DROP TABLE prod_on_ord; Must delete objects in the order of referential integrity constraints, unless the constraints are “cascaded” during the delete process. SQL Statement is: DROP TABLE prod_on_ord CASCADE CONSTRAINTS;

SQL INSERT Statement Used to “populate” a table with data. Used to enter one row of data. Character/string data must be entered surrounded by single quotes. Dates are best entered using the Oracle default format of dd-mon-yy or dd-mon-yyyy. For example, today’s date in the Oracle default format is: 02-feb-2006

INSERT INTO ord VALUES (14452, ’02-feb-06’, 234, ‘A1’); INSERT INTO ord VALUES (23415, SYSDATE, 2100, ‘B3’); INSERT INTO ord VALUES (14419, ’08-jul-1999’, 320, ‘02’); INSERT INTO ord (order_no, customer_no) VALUES (2231, 334); COMMIT; Using the original ord table example, these are sample INSERT statements used to add rows to the table

Purpose of the COMMIT Statement Some SQL statements act directly to save results on disk, others do not. CREATE produces a data object on disk; not just in main memory. INSERT adds a row of data in main memory. To save data from memory to disk, use the COMMIT statement.

Deleting Data from a Table DELETE FROM ord WHERE ord_no = 3344; DELETE FROM prod WHERE cost < 1.56; DELETE FROM prod_on_ord WHERE price < 1.25 AND quantity < 3;

Changing Existing Data in a Table UPDATEord SETorder_date = ’22-jan-06’ WHEREorder_no = 14452; UPDATEord SETorder_date = SYSDATE WHEREorder_no = 14452; UPDATEprod SETcost = 0 WHEREdescription = ‘bolt’;

Retrieving Data from a Table General Syntax for accessing data from a table SELECT [all or distinct] (what columns) FROM (table) WHERE (condition) GROUP BY (grouping fields) HAVING (condition) ORDER BY (sort fields)

Example of Retrieving Data from a Table SELECT* FROM ord; SELECT * FROM prod’ SELECT order_id, order_date FROM ord; SELECT order_id, order_date FROM ord WHERE cust_id = ‘6511’; The * means retrieve all columns. The FROM statement, without a WHERE statement, means retrieve all rows.

Retrieving Info from Oracle SQLPlus command to see structure of data object: DESCRIBEemp; SQL command to see contents of your tablespace: SELECT table_name FROM tabs; Tabs is a data view in the Oracle data dictionary containing information about all database objects in a given tablespace.