ITBIS373 Database Development Lecture 2 - Chapter 2 Creating And Modifying Database Tables.

Slides:



Advertisements
Similar presentations
A Guide to Oracle9i1 Creating and Modifying Database Tables Chapter 2.
Advertisements

SQL’s Data Definition Language (DDL) n DDL statements define, modify and remove objects from data dictionary tables maintained by the DBMS n Whenever you.
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.
1 A GUIDE TO ORACLE8 CHAPTER 2: Creating and ModifyingDatabaseTables 2.
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.
1 Chapter 2: Creating and Modifying Database Tables.
A Guide to Oracle9i1 Using SQL Queries to Insert, Update, Delete, and View Data Chapter 3.
Guide to Oracle 10g1 Chapter 2: Creating and Modifying Database Tables.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
Creating Database Tables © Abdou Illia MIS Spring /21/2015.
Introduction to Structured Query Language (SQL)
Creating Database Tables CS 320. Review: Levels of data models 1. Conceptual: describes WHAT data the system contains 2. Logical: describes HOW the database.
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.
Using SQL Queries to Insert, Update, Delete, and View Data © Abdou Illia MIS Spring 2015 Wednesday 1/28/2015 Chapter 3A.
1 Chapter 2: Creating and Modifying Database Tables.
Oracle Data Definition Language (DDL)
Guide to Oracle10G1 Using SQL Queries to Insert, Update, Delete, and View Data Chapter 3.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
ASP.NET Programming with C# and SQL Server First Edition
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Database Design lecture 3_1 1 Database Design Lecture 3_1 Data definition in SQL.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
ITBIS373 Database Development
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.
10 Copyright © 2009, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
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.
1 A Guide to SQL Chapter 2. 2 Introduction Mid-1970s: SQL developed under the name SEQUEL at IBM by San Jose research facilities to be the data manipulation.
SQL: DDL John Ortiz Cs.utsa.edu.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
ITBIS373 Database Development Lecture 3a - Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
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.
Copyright  Oracle Corporation, All rights reserved. Introduction.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Managing Constraints. 2 home back first prev next last What Will I Learn? Four different functions that the ALTER statement can perform on constraints.
Lecture5: SQL Overview, Oracle Data Type, DDL and Constraints Ref. Chapter6 Lecture4 1.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
1 Chapter 2: Creating and Modifying Database Objects.
Sql DDL queries CS 260 Database Systems.
Oracle 9i. Agenda Start and exit SQL Plus (General) Start and exit SQL Plus (Tah 1006) Syntax Create a new user Create a new table Enter data into a new.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
Academic Year 2015 Autumn. MODULE CC2006NI: Data Modelling and Database Systems Academic Year 2015 Autumn.
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.
3 A Guide to MySQL.
CIT 214 Introduction to Database Management
Guide to Oracle 10g Chapter 2: Creating and Modifying Database Tables.
Managing Tables, Data Integrity, Constraints by Adrienne Watt
SQL: Schema Definition and Constraints Chapter 6 week 6
SQL and SQL*Plus Interaction
ORACLE SQL Developer & SQLPLUS Statements
SQL data definition using Oracle
Oracle Data Definition Language (DDL)
Chapter 2: Creating And Modifying Database Tables
Introduction to Oracle
Presentation transcript:

ITBIS373 Database Development Lecture 2 - Chapter 2 Creating And Modifying Database Tables

Guide to Oracle 10g2 Objectives After completing this chapter, you should be able to: Use structured query language (SQL) commands to create, modify, and drop database tables Explain Oracle user schemas Define and create Oracle database tables Debug Oracle SQL commands Use online help resources available through the Oracle Technology Network (OTN)

Guide to Oracle 10g3 Objectives (continued) View information about your database tables using Oracle 10g data dictionary views Modify and delete database tables using SQL*Plus

Guide to Oracle 10g4 Introduction to SQL Structured query language (SQL) Standard query language for relational databases Consists of about 30 commands Enables users to create database objects and manipulate and view data SQL-99 Most recent version

Guide to Oracle 10g5 Introduction to SQL (continued) Structured query language (SQL) (continued) Basic categories for SQL commands Data definition language (DDL) Data manipulation language (DML) Reserved words SQL command words

Guide to Oracle 10g6 Oracle 10g User Accounts User account Created for each user Identified using unique username and password User schema Area of database belonging to user Database objects Also called schema objects Objects in user schema

Guide to Oracle 10g7 Defining Oracle 10g Database Tables Tables Primary data objects in relational database Constraints Restrictions on data values that column can store Oracle naming standard Rules that Oracle corporation has established for naming all database objects

Guide to Oracle 10g8 Defining Oracle 10g Database Tables (continued) Oracle naming standard One to 30 characters long Contain letters, numbers, and special symbols $, _, and # Begin with character CREATE TABLE SQL syntax CREATE TABLE tablename (columnname1 data_type, columnname2 data_type, …)

Guide to Oracle 10g9 Oracle 10g Data Types Data type Specifies kind of data that column stores Provides means for error checking Enable DBMS to use storage space more efficiently Basic types Character Number Date/time Large object

Guide to Oracle 10g10 Character Data Types VARCHAR2 Variable-length character data Syntax columnname VARCHAR2(maximum_size) CHAR Fixed-length character data Syntax columnname CHAR[(maximum_size)]

Guide to Oracle 10g11 Character Data Types (continued) Unicode Standardized technique that provides way to encode data in diverse languages NVARCHAR2 Counterpart of VARCHAR2 Uses Unicode coding NCHAR Counterpart of CHAR Uses Unicode encoding

Guide to Oracle 10g12 Number Data Types NUMBER Used for all numeric data Syntax columnname NUMBER [([precision,] [scale])] Precision Total number of digits both to left and right of decimal point

Guide to Oracle 10g13 Number Data Types (continued) Integer number syntax columnname NUMBER(precision) Fixed-point number Contains specific number of decimal places Column declaration specifies both precision and scale Example price NUMBER(5, 2)

Guide to Oracle 10g14 Number Data Types (continued) Floating-point number Contains variable number of decimal places Syntax columnname NUMBER Example s_gpa NUMBER

Guide to Oracle 10g15 Date And Time Data Types Datetime data subtypes Store actual date and time values DATE TIMESTAMP Interval data subtypes Store elapsed time interval between two datetime values INTERVAL YEAR TO MONTH INTERVAL DAY TO SECOND

Guide to Oracle 10g16 Date And Time Data Types (continued) DATE Stores dates from December 31, 4712 BC to December 31, AD 4712 Default date format DD-MON-YY Default time format HH:MI:SS AM Syntax: columnname DATE

Guide to Oracle 10g17 Date And Time Data Types (continued) TIMESTAMP Stores date values similar to DATE data type, except it also stores fractional seconds in addition to the century, year, month, day, hour, minute, and second. Syntax columnname TIMESTAMP (fractional_seconds_precision) Example 04-SEP DD-Mon-YY HH.MM.SS.FFFFFF If you omit the fractional_seconds_precision specification, the default value is six decimal places.

Guide to Oracle 10g18 Date And Time Data Types (continued) INTERVAL YEAR TO MONTH Stores time interval expressed in years and months Syntax +|– elapsed_years-elapsed_months Ex: : specifies a positive time interval of 2 years and 11 months. You use the following command to declare an INTERVAL YEAR TO MONTH data column: INTERVAL YEAR [(year_precsion)] TO MONTH If you omit the Year_precsion value in the column declaration, the default value is 6, which enables the column to display a maximum interval 0f 999,999 years.)

Guide to Oracle 10g19 CREATE TABLE student (s_id VARCHAR2(6), s_last VARCHAR2(30), s_first VARCHAR2(30), s_mi CHAR(1), s_address VARCHAR2(25), s_city VARCHAR2(20), s_state CHAR(2), s_zip VARCHAR2(10), s_phone VARCHAR2(10), s_class CHAR(2), s_dob DATE, s_pin NUMBER(4), f_id NUMBER(6), time_enrolled INTERVAL YEAR TO MONTH, CONSTRAINT student_s_id_pk PRIMARY KEY (s_id), CONSTRAINT student_f_id_fk FOREIGN KEY (f_id) REFERENCES faculty(f_id)); NSERT INTO student VALUES ('JO100', 'Jones', 'Tammy', 'R', '1817 Eagleridge Circle', 'Tallahassee', 'FL', '32811', ' ', 'SR', TO_DATE('07/14/1985', 'MM/DD/YYYY'), 8891, 1, TO_YMINTERVAL('3-2'));

Guide to Oracle 10g20 Date And Time Data Types (continued) INTERVAL DAY TO SECOND Stores time interval expressed in days, hours, minutes, and seconds Syntax +|– elapsed_days elapsed_hours:elapsed_minutes:elapsed_se conds

Guide to Oracle 10g21 The following data value expresses a negative time interval of 4 days, 3 hours, 20 minutes and 32 seconds: :20:32.00 The basic syntax to define an INTERVAL DAY TO SECOND data column is as follows: Columnname INTERVAL DAY [( leading_precision)] TO SECOND{(fractional_seconds_precision)] The default values for these expressions are 2 and 6 respectively.

Guide to Oracle 10g22 CREATE TABLE COURSE_SECTION (c_sec_id NUMBER(6), course_no VARCHAR2(7) CONSTRAINT course_section_courseid_nn NOT NULL, term_id NUMBER(6) CONSTRAINT course_section_termid_nn NOT NULL, sec_num NUMBER(2) CONSTRAINT course_section_secnum_nn NOT NULL, f_id NUMBER(6), c_sec_day VARCHAR2(10), c_sec_time DATE, c_sec_duration INTERVAL DAY TO SECOND, loc_id NUMBER(6), max_enrl NUMBER(4) CONSTRAINT course_section_maxenrl_nn NOT NULL, CONSTRAINT course_section_csec_id_pk PRIMARY KEY (c_sec_id), CONSTRAINT course_section_cid_fk FOREIGN KEY (course_no) REFERENCES course(course_no), CONSTRAINT course_section_loc_id_fk FOREIGN KEY (loc_id) REFERENCES location(loc_id), CONSTRAINT course_section_termid_fk FOREIGN KEY (term_id) REFERENCES term(term_id), CONSTRAINT course_section_fid_fk FOREIGN KEY (f_id) REFERENCES faculty(f_id));

Guide to Oracle 10g inserting records into COURSE_SECTION INSERT INTO course_section VALUES (1, 'MIS 101', 4, 1, 2, 'MWF', TO_DATE('10:00 AM', 'HH:MI AM'), TO_DSINTERVAL('0 00:50:00.00'), 1, 140); INSERT INTO course_section VALUES (2, 'MIS 101', 4, 2, 3, 'TR', TO_DATE('09:30 AM', 'HH:MI AM'), TO_DSINTERVAL('0 01:15:00.00'), 7, 35); INSERT INTO course_section VALUES (3, 'MIS 101', 4, 3, 3, 'MWF', TO_DATE('08:00 AM', 'HH:MI AM'), TO_DSINTERVAL('0 00:50:00.00'), 2, 35); INSERT INTO course_section VALUES (4, 'MIS 301', 4, 1, 4, 'TR', TO_DATE('11:00 AM', 'HH:MI AM'), TO_DSINTERVAL('0 01:15:00.00'), 6, 35);

Guide to Oracle 10g24 Large Object (LOB) Data Types Store binary data such as: Digitized sounds or images References to binary files from word processor or spreadsheet General syntax columnname Lob_data_type

Guide to Oracle 10g25 Large Object (LOB) Data Types (continued)

Guide to Oracle 10g26 CREATE TABLE faculty (f_id NUMBER(6), f_last VARCHAR2(30), f_first VARCHAR2(30), f_mi CHAR(1), loc_id NUMBER(5), f_phone VARCHAR2(10), f_rank VARCHAR2(9), f_super NUMBER(6), f_pin NUMBER(4), f_image BLOB, or f_image Bfile CONSTRAINT faculty_f_id_pk PRIMARY KEY(f_id), CONSTRAINT faculty_loc_id_fk FOREIGN KEY (loc_id) REFERENCES location(loc_id)); INSERT INTO faculty VALUES (1, 'Marx', 'Teresa', 'J', 9, ' ', 'Associate', 4, 6338, EMPTY_BLOB()); INSERT INTO faculty VALUES (2, 'Zhulin', 'Mark', 'M', 10, ' ', 'Full', NULL, 1121, brown.jpg ); INSERT INTO faculty VALUES (3, 'Langley', 'Colin', 'A', 12, ' ', 'Assistant', 4, 9871, sealy.gpg) ; INSERT INTO faculty VALUES (4, 'Brown', 'Jonnel', 'D', 11, ' ', 'Full', NULL, 8297, EMPTY_BLOB()) ; INSERT INTO faculty VALUES (5, 'Sealy', 'James', 'L', 13, ' ', 'Associate', 1, 6089, EMPTY_BLOB()) ;

Guide to Oracle 10g27 Constraints Rules that restrict data values that can be entered into column Types of constraints: Integrity constraints Value constraints Table constraint Restricts data value with respect to all other values in table. An example of a table constraint is a primary key constraint, which specifies that a column value must be unique and cannot appear in this column in more than one table row.

Guide to Oracle 10g28 Constraints (continued) Column constraint Limits value that can be placed in specific column. Example of column constraints are value constraints, which specify that a certain value or set of values must be used, and NOT NULL constraint s which specify that a value cannot be NULL. Constraint definitions should be placed either: At end of CREATE TABLE command after table columns declared Within each column definition

Guide to Oracle 10g29 Constraints (continued) Constraint naming convention tablename_columnname_constraintID

Guide to Oracle 10g30 Common ConstraintID Abbreviations

Guide to Oracle 10g31 Integrity Constraints Primary key Syntax (within a column declaration) CONSTRAINT constraint_name PRIMARY KEY Syntax (at end of table definition) CONSTRAINT constraint_name PRIMARY KEY (columnname)

Guide to Oracle 10g32 Integrity Constraints (continued) Foreign key is a column constraint that the value a user inserts in column must exist as primary key in referenced table Syntax (placed at end of table definition) CONSTRAINT constraint_name FOREIGN KEY (columnname) REFERENCES primary_key_tablename (primary_key_columnname)

Guide to Oracle 10g33 CREATE TABLE COURSE_SECTION (c_sec_id NUMBER(6), course_no VARCHAR2(7) CONSTRAINT course_section_courseid_nn NOT NULL, term_id NUMBER(6) CONSTRAINT course_section_termid_nn NOT NULL, sec_num NUMBER(2) CONSTRAINT course_section_secnum_nn NOT NULL, f_id NUMBER(6), c_sec_day VARCHAR2(10), c_sec_time DATE, c_sec_duration INTERVAL DAY TO SECOND, loc_id NUMBER(6), max_enrl NUMBER(4) CONSTRAINT course_section_maxenrl_nn NOT NULL, CONSTRAINT course_section_c _ sec_id_pk PRIMARY KEY (c_sec_id), CONSTRAINT course_section_course_no_fk FOREIGN KEY (course_no) REFERENCES course(course_no), CONSTRAINT course_section_loc_id_fk FOREIGN KEY (loc_id) REFERENCES location(loc_id), CONSTRAINT course_section_termid_fk FOREIGN KEY (term_id) REFERENCES term(term_id), CONSTRAINT course_section_fid_fk FOREIGN KEY (f_id) REFERENCES faculty(f_id));

Guide to Oracle 10g34 Integrity Constraints (continued) Foreign key (continued) Syntax (placed within table definition) CONSTRAINT constraint_name REFERENCES primary_key_tablename (primary_key_columnname) Composite key Syntax CONSTRAINT constraint_name PRIMARY KEY (columnname1, columnname2 …)

Guide to Oracle 10g35 EX OF Composite KEY CREATE TABLE ENROLLMENT (s_id VARCHAR2(6), c_sec_id NUMBER(6), grade CHAR(1), CONSTRAINT enrollment_s_id_c_sec_id_pk PRIMARY KEY (s_id, c_sec_id), CONSTRAINT enrollment_sid_fk FOREIGN KEY (s_id) REFERENCES student(s_id), CONSTRAINT enrollment_csecid_fk FOREIGN KEY (c_sec_id) REFERENCES course_section (c_sec_id));

Guide to Oracle 10g36 Value Constraints Value constraints: Commonly used value constraints include: CHECK conditions Ex: CONSTRAINT course_credits_cc CHECK (credits >0) AND (credits < 12)) NOT NULL constraint Ex: S_last VARCHAR2(30) CONSTRAINT student_s_last_nn NOT NULL

Guide to Oracle 10g37 DEFAULT constraint Ex: s_state CHAR(2) DEFAULT ‘BH’ UNIQUE constraint: it basically the same as primary key constraint, except NULL value are allowed in the column. CONSTRAINT term_term_desc_uk UNIQUE (term_desc )

Guide to Oracle 10g38 Creating Database Tables Using SQL*Plus Start SQL*Plus Type username and password Type SQL commands at SQL prompt End each command with semicolon (;) Press Enter to submit commands

Guide to Oracle 10g39 Creating Database Tables Using SQL*Plus (continued) SQL*Plus interpreter Checks command for syntax errors Submits command to database SQL commands are not case sensitive When creating database tables that contain foreign key references Must first create table in which foreign key is primary key

Guide to Oracle 10g40 SQL Command to Create the LOCATION Table

Guide to Oracle 10g41 Creating and Editing SQL Commands Using a Text Editor Good approach for entering commands: Type commands into text editor such as Notepad Copy commands, then paste into SQL*Plus Execute commands Script Text file that contains several related SQL commands

Guide to Oracle 10g42 Using Oracle Online Help Resources to Debug SQL Commands Syntax error SQL*Plus interpreter displays error information Line number within command that caused error Position of error within line Error code and description of error

Guide to Oracle 10g43 Using Oracle Online Help Resources To Debug SQL Commands (continued) Oracle 10g error codes have: 3-character prefix (such as ORA) 5-digits Causes of SQL command errors are not always readily apparent Need to retrieve more information about error Connect to Oracle Technology Network (OTN) Web Site and search for error code

Guide to Oracle 10g44 Using Oracle Online Help Resources To Debug SQL Commands (continued) Last resort debugging technique Create table multiple times Each time adding column declaration Repeat process until you find declaration causing error Drop table command To delete table from dictionary syntax: DROP TABLE tablename

Guide to Oracle 10g45

Guide to Oracle 10g46 Exiting SQL*Plus Type exit at SQL prompt Click File on menu bar, and then click Exit Click Close button on program window title bar

Guide to Oracle 10g47 Viewing Information about Tables DESCRIBE command View column names and data types of table Syntax DESCRIBE tablename Oracle 10g data dictionary Consists of tables that contain information about structure of database - When the DBA creates a new database, the system creates data dictionary in user schema named SYS The Oracle 10g DBMS automatically updates the data dictionary tables as users create, update, and delete database objects.

Guide to Oracle 10g48 Viewing Information about Tables (continued) View Database object DBMS bases on actual database table Enables DBMS to present table data in different format based on needs of users

Guide to Oracle 10g49 Viewing Information about Tables (continued) Data dictionary views are divided into three general categories USER- shows the objects in the current user’s name. ALL- shows both the objects in the current user’s scheme and the objects that the user has privileges to manipulate. DBA- Allows users who are DBAs to view information about all database objects. Syntax SELECT view_columnname1, view_columnname2 … FROM prefix_object;

Guide to Oracle 10g50 In this syntax, View_Columnname1, View_Column2 reference the names of the columns in the view that you wish to retrieve. Prefix: specfies the view category, and can have the value USER,DBA, or ALL. Object is the type of database object you are examining, such as TABLES, or CONSTRAINTS.

Guide to Oracle 10g51

Guide to Oracle 10g52 Database Objects with Data Dictionary Views

Guide to Oracle 10g53 You can retrieve information from these views using commands similar to the ones you used to retrieve information about your database table, the command to retrieve the names of all of your database objects is: SELECT object_name FROM user_objects ; All the data dictionary views have different columns. To determine the names of the columns in specific database views, you use the DESCRIBE command along with the view name. Fig 2-9 shows a description of the column names in the USER_CONSTRAINTS data dictionary views.

Guide to Oracle 10g54

Guide to Oracle 10g55 To View your table Constraints

Guide to Oracle 10g56 To List the FACULTY table constraints:

Guide to Oracle 10g57 Modifying and Deleting Database Tables Plan tables carefully to avoid having to change structure of database tables later Unrestricted action Some specifications of tables can always be modified Restricted action Table specifications that can be modified only in certain situations

Guide to Oracle 10g58 Unrestricted Actions when Modifying Database Tables

Guide to Oracle 10g59

Guide to Oracle 10g60 Deleting and Renaming Existing Tables DROP TABLE command Delete table Syntax DROP TABLE tablename; DROP TABLE tablename CASCADE CONSTRAINTS;

Guide to Oracle 10g61 To drop a table that contains columns that other tables reference as foreign keys, you have two options. One option is to first drop all the tables that contain the foreign key references. For example, to delete the LOCATION table, you could first delete the FACULTY table, and then you could delete the LOCATION table. The second option is first to delete all of the foreign key constraints that reference a table, you use the CASCADE CONSTRAINTS option in the DROP TABLE command, which has the following syntax: DROP TABLE tablename CASCADE CONSTRAINTS;

Guide to Oracle 10g62

Guide to Oracle 10g63 Deleting and Renaming Existing Tables (continued) RENAME TO command Syntax RENAME old_tablename TO new_tablename; Ex: RENAME faculty TO nw_faculty;

Guide to Oracle 10g64 Adding Columns to Existing Tables Add new column to table Syntax ALTER TABLE tablename ADD(columnname data_declaration constraints); Ex: ALTER TABLE faculty ADD (start_date DATE);

Guide to Oracle 10g65 Modifying Existing Column Data Definitions Modify existing column’s data declaration Syntax ALTER TABLE tablename MODIFY(columnname new_data_declaration); EX: ALTER TABLE faculty MODIFY (f_rank CHAR(4));

Guide to Oracle 10g66 Deleting a Column Data stored in deleted column removed from database Syntax ALTER TABLE tablename DROP COLUMN columnname;

Guide to Oracle 10g67 Renaming a Column Syntax ALTER TABLE tablename RENAME COLUMN old_columnname TO new_columnname; Ex: ALTER TABLE faculty RENAME COLUMN f_rank TO faculty_rank ;

Guide to Oracle 10g68 Adding and Deleting Constraints Add constraint to existing table Syntax ALTER TABLE tablename ADD CONSTRAINT constraint_name constraint_definition; EX ALTER TABLE faculty ADD CONSTRAINT faculty_f_pin_uk UNIQUE(f_pin); Remove existing constraint Syntax ALTER TABLE tablename DROP CONSTRAINT constraint_name;

Guide to Oracle 10g69 Remove existing constraint Syntax ALTER TABLE tablename DROP CONSTRAINT constraint_name; EX ALTER TABLE faculty DROP CONSTRAINT faculty_f_pin_uk;

Guide to Oracle 10g70 Enabling and Disabling Constraints Constraint enabled DBMS enforces constraint when users attempt to add new data to database Disable existing constraint syntax ALTER TABLE tablename DISABLE CONSTRAINT constraint_name; Enable existing constraint syntax ALTER TABLE tablename ENABLE CONSTRAINT constraint_name;

Guide to Oracle 10g71 EX : ALTER TABLE faculty DISABLE CONSTRAINT faculty_loc_id_fk; ALTER TABLE faculty ENABLE CONSTRAINT faculty_loc_id_fk;

Guide to Oracle 10g72 Summary SQL commands include Data defintion language (DDL) commands Data manipulation language (DML) commands Each user account owns table and data objects in own area of database Called user schema When creating database table specify table name, column names, data type, and column sizes

Guide to Oracle 10g73 Summary (continued) Constraints restrict data values that users can enter into database columns When SQL commands have errors interpreter reports: Line number Position of character causing error Returns error code and description Use describe command to display table info