Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.

Slides:



Advertisements
Similar presentations
Data Definition and Integrity Constraints
Advertisements

MySQL. To start go to Login details: login: labuser password:macimd15 – There.
Assignment6-1 Assignment6-2 Due Wednesday, March 13 1.
Chapter 6 SQL. Agenda Data Definition Language (DDL) Access Control.
1 A GUIDE TO ORACLE8 CHAPTER 2: Creating and ModifyingDatabaseTables 2.
1 Chapter 2: Creating and Modifying Database Tables.
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.
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
Database Management System LICT 3011 Eyad H. Elshami.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Chapter 6 SQL. Agenda Data Definition Language (DDL) Access Control.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
Introduction to SQL  SQL or sequel  It is a standardised language with thousands of pages in the standard  It can be in database system through GUI,
Oracle Data Definition Language (DDL)
Copyright © Curt Hill SQL The Data Definition Language.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 6 SQL Data Definition Language Chapter 7 in Textbook.
Chapter 8 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
CSC 2720 Building Web Applications Database and SQL.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
1 Copyright © 2006, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
Chapter 5: Part 1: DDL STRUCTURED QUERY LANGUAGE (SQL)
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.
CS 3630 Database Design and Implementation. Assignment 3 Style! Agreement between database designer and the client. UserName1_EasyDrive UserName2_EasyDrive.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Creating Tables and Inserting Records -- Not easy to edit! -- check constraints! Create table test1 ( C1 char(5) primary key, C2 Varchar2(15) not null.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Oracle & SQL Introduction. Database Concepts Revision DB? DBMS? DB Application? Application Programs? DBS? Examples of DBS? Examples of DBMS? 2Oracle.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
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.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
SQL: Part 1 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram. Not for commercial.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
1 Chapter 2: Creating and Modifying Database Objects.
Sql DDL queries CS 260 Database Systems.
Week 8-9 SQL-1. SQL Components: DDL, DCL, & DML SQL is a very large and powerful language, but every type of SQL statement falls within one of three main.
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
Data Definition Language
CS 3630 Database Design and Implementation. Null Value The value of an attribute could be NULL NOT known at the moment or NOT Applicable Example Cell.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
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.
CS242 SQL. What is SQL? SQL:  stands for Structured Query Language  allows you to access a database  is an ANSI standard computer language  can execute.
3 A Guide to MySQL.
CS 3630 Database Design and Implementation
Managing Tables, Data Integrity, Constraints by Adrienne Watt
SQL: Schema Definition and Constraints Chapter 6 week 6
CS 3630 Database Design and Implementation
ORACLE SQL Developer & SQLPLUS Statements
DATABASE MANAGEMENT SYSTEM
STRUCTURED QUERY LANGUAGE
SQL data definition using Oracle
Oracle Data Definition Language (DDL)
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
CS3220 Web and Internet Programming SQL and MySQL
CS3220 Web and Internet Programming SQL and MySQL
SQL (Structured Query Language)
Presentation transcript:

Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive Reset password to Ken at from your UWP account if you forget your password 1

Login to Your Oracle Account SQL*Plus Oracle 11 All labs in Ullrich Not available from home 2

Change Your Oracle Password -- Oracle Command Prompt SQL> -- Change your password -- Remember your new password! SQL> Alter User yourUserName identified by newPassword; -- Every ANSI SQL standard command ends with ; 3

Structured Query Language (SQL) One language for Relational Databases ANSI Standard Oracle: SQL*Plus MS SQL Server: Transact-SQL IBM DB2 MySQL Sybase... 4

Structured Query Language (SQL) Case insensitive (like VB) Free style (like C++ and Java) Statement terminator – semicolon (like C++ and Java) Programming Rule: Style Each clause of a query on a separate line When creating tables Each field on a separate line Each table constraint on a separate line 5

Structured Query Language (SQL) DDL (Data Definition Language) Create Table (user)... Drop Table (user)... Alter Table (user)... DML (Data Manipulation language) Select * From Branch … Insert into Branch... Update branch... Delete from BRANCH... 6

Oracle Data Types Char(size) fixed length string up to 2000 bytes default is 1 byte blanks are padded on right when fewer chars entered Varchar2(size) variable size string up to 2000 bytes must specify the limit (size) Varchar(size) same as Varchar2(size) better to use Varchar2 7

Oracle Data Types Integer, int, smallint Float Date Valid dates from 1-Jan-4712 B.C. to 31-Dec-4712 A.D. Default format: DD-MON-YY 23-Mar-09 Including time 8

Oracle Data Types Number(l, d) l: length (total) d: decimal digits number (5, 2): largest value is Decimal(l, d), Numeric(l, d) same as number(l, d) SQL standard blob: binary large object, up to 4 GB clob: character large object, up to 4 GB raw(size): raw binary data, up to 2000 bytes... 9

Create a Table SQL> Create Table Test1 ( C1 char(5) Primary Key, C2 Varchar2(50), C3 Integer, C4 Date); 10

Show Table Schema SQL> Describe Test1 Or SQL> Desc Test1 Describe is a SQL*Plus command and no semicolon is required. 11

Insert Records Insert into Test1 Values (‘cs363', ‘s1', 44, ‘28-feb-12’); Insert into Test1 Values (‘cs334', ‘s2', 45, ‘29-feb-12’); One record at a time! 12

Retrieve Records Select * From test1; -- Each clause on a separate line Select * From Test1; 13

Entity Integrity Insert into Test1 Values (‘cs363', ‘q2', 17, ‘2-Mar-12’); PK must be Unique! 14

Null Values Insert into Test1 Values (‘cs387', ‘q2', 17, null); Null is a key word, not a string! NULL, null and Null are the same SQL is not case sensitive 15

Entity Integrity Insert into Test1 Values (null, ‘q2', 17, ‘2-Mar-12’); PK cannot be null! 16

Command Commit DDL commands are sent back to server and executed there DML commands are executed at client site Use commit to send results back to server 17

Update Records Update test1 Set c3 = 50 Where c1 = ‘cs363’; 18

Delete Records Delete from test1 Where c1 = ‘cs363’; -- select to check Delete from test1; -- select to check -- desc to check 19

Drop Table Drop table test1; Desc test1 -- to check ERROR: ORA-04043: object test1 does not exist 20

Log out SQL> exit 21

Schedule Assignment 7 Due Monday, March 18 at 5 pm Test 1 Wednesday, March 20 Lab

Database Schema Branch (Bno…) Staff (Sno…Bno) Owner (Ono…) PropertyForRent (Pno…Ono) Renter (Rno…) Viewing (Rno, Pno, ViewDate…) 23

In what order to create the tables? Branch (Bno…) Staff (Sno…Bno) Owner (Ono…) PropertyForRent (Pno…Ono) Renter (Rno…) Viewing (Rno, Pno, ViewDate…) Will it work? YES! Branch (Bno…) Staff (Sno…Bno) PropertyForRent (Pno…Ono) Owner (Ono…) Viewing (Rno, Pno, ViewDate…) Renter (Rno…) Will it work? NO! 24

In what order to drop the tables? Viewing (Rno, Pno, ViewDate…) Staff (Sno…Bno) PropertyForRent (Pno…Ono) Owner (Ono…) Renter (Rno…) Branch (Bno…) Will it work? YES! Branch (Bno…) Staff (Sno…Bno) Owner (Ono…) PropertyForRent (Pno…Ono) Renter (Rno…) Viewing (Rno, Pno, ViewDate…) Will it work? NO! 25

Insert Rows The PK must be unique The foreign key value must exist in the parent table if FK is provided FK can be null, meaning not known at the time 26

Insert Rows Insert into Branch: no problem Insert into Staff: Cannot insert a staff with Bno being ‘B123’ if Branch table has no ‘B123’ in Bno column FK can be null, meaning not known at the time Branch BnoPhone… B101 B205 Staff SnoPhoneBno SG100B101 SG363Null SA200 27

Delete Rows No records in other tables reference the record to be deleted. 28

Delete Rows Delete from Staff: no problem Delete from Branch: Delete branch 'B101' What about staff in 'B101‘? Branch BnoPhone… B205 Staff SnoPhoneBno SG100B101 SG363Null SA200B101 29

ANSI SQL Solutions In ANSI SQL, there are five choices No Action Cannot delete Set to Null Set to Default No Check No good Cascade Delete all staff in 'B101' from Staff table when deleting branch ‘B101’ Dangerous! 30

Oracle Solutions 31

Update Record Update table Staff ‘B101’ of SG100 to ‘B205’ New value must exist in Branch Update table Branch ‘B101’ to ‘B303’ Five choices in ANSI SQL, only No Action is implemented in Oracle Branch BnoPhone… B101 B205 Staff SnoPhoneBno SG100B101 SG363Null SA200B205 32

Integrity Rules: Constraints Column Constraints Table Constraints 33

Column Constraints Primary key Sno Char(4) Primary Key, Alternate Key SSN Char(9) Unique, Foreign Key BNo char(4) References Branch, -- when attribute has the same name BNo char(4) References Branch(B_no), -- when attribute has different names BNo char(4) References Branch on Delete Cascade, -- Do NOT use “Foreign Key” in column constaints! 34

Column Constraints Domain constraint Salary Number Check (Salary > and Salary < ), PType varchar2(6) Check (PType in ('House', 'Flat', 'Appt')), -- Strings are in single quotes, NOT double quotes Bno Char(4) Default 'B363' References Branch, Rent Float Check (Rent Between 200 and 400), -- between is Inclusive Required data LName Varchar2(20) Not Null, -- Can be specified only by column constraint 35

Column Constraints Create table Staff ( SNo char(4) Primary Key, Bno Char(4) Default 'B363' References Branch on Delete Cascade, FName Varchar2(20) Not Null, LName Varchar2(20) Not Null, -- assuming functions DateDiff and Now DOB Date Not Null Check (DateDiff(Year, Now, DOB) >= 16), Salary Number Check (Salary Between and ), SSN Char(9) Unique, Tel_No Char(12)); -- Primary Key, Unique, References should be the last constraint for a column -- Do not use Foreign key for column constraints, only use References 36