© 2007 by Prentice Hall3-1 Introduction to Oracle 10g Chapter 3 Creating, Modifying, Renaming, and Deleting Database Tables James Perry and Gerald Post.

Slides:



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

CIT 613: Relational Database Development using SQL Revision of Tables and Data Types.
9 Creating and Managing Tables. Objectives After completing this lesson, you should be able to do the following: Describe the main database objects Create.
Data Definition Language (DDL)
Database Chapters.
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.
Module 4: Creating Data Types and Tables. Overview Creating Data Types Creating Tables Generating Column Values Generating Scripts.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
Representing Data Elements Gayatri Gopalakrishnan.
1 A GUIDE TO ORACLE8 CHAPTER 2: Creating and ModifyingDatabaseTables 2.
1 Chapter 2: Creating and Modifying Database Tables.
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.
Creating Database Tables © Abdou Illia MIS Spring /21/2015.
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.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
1 Chapter 2: Creating and Modifying Database Tables.
Oracle Data Definition Language (DDL)
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Oracle for Software Developers. What is a relational database? Data is represented as a set of two- dimensional tables. (rows and columns) One or more.
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 8 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Oracle Database Administration
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.
11 3 / 12 CHAPTER Databases MIS105 Lec15 Irfan Ahmed Ilyas.
10-1 Copyright  Oracle Corporation, All rights reserved. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
Module 3: Creating Data Types and Tables. Overview Working with Data Types Working with Tables Generating Column Values Generating Scripts.
SCUHolliday - coen 1788–1 Schedule Today u Modifications, Schemas, Views. u Read Sections (except and 6.6.6) Next u Constraints. u Read.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Advanced Database CS-426 Week 1 - Introduction. Database Management System DBMS contains information about a particular enterprise Collection of interrelated.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
SQL CREATING AND MANAGING TABLES lecture4 1. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically.
© 2007 by Prentice Hall4-1 Introduction to Oracle 10g Chapter 4 Modifying Data and Auditing Table Operations James Perry and Gerald Post.
Fox MIS Spring 2011 Database Week 6 ERD and SQL Exercise.
1 Chapter 2: Creating and Modifying Database Objects.
Sql DDL queries CS 260 Database Systems.
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
© 2007 by Prentice Hall2-1 Introduction to Oracle 10g Chapter 2 Overview of SQL and SQL*Plus James Perry and Gerald Post.
Academic Year 2015 Autumn. MODULE CC2006NI: Data Modelling and Database Systems Academic Year 2015 Autumn.
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.
CSCI N311: Oracle Database Programming 5-1 Chapter 15: Changing Data: insert, update, delete Insert Rollback Commit Update Delete Insert Statement –Allows.
Lecture # 24 Introduction to SQL Muhammad Emran Database Systems.
 CONACT UC:  Magnific training   
8 Copyright © 2005, Oracle. All rights reserved. Managing Schema Objects.
Creating and Managing Tables. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically represents subsets.
Introduction To Oracle
CS 3630 Database Design and Implementation
TABLES AND INDEXES Ashima Wadhwa.
Managing Tables, Data Integrity, Constraints by Adrienne Watt
SQL data definition using Oracle
ORACLE I 2 Salim Phone : YM : talim_bansal.
Oracle Data Definition Language (DDL)
Chapter 2: Creating And Modifying Database Tables
SQL (Structured Query Language)
Presentation transcript:

© 2007 by Prentice Hall3-1 Introduction to Oracle 10g Chapter 3 Creating, Modifying, Renaming, and Deleting Database Tables James Perry and Gerald Post

© 2007 by Prentice Hall3-2 Chapter Outline Designing a Database Understanding Oracle User Accounts Further Instructions for Personal Oracle Users Creating Tables Defining and Using Constraints Altering a Table and Its Constraints Displaying Tables’ Names and Constraints Dropping, Reinstating, and Renaming Tables Creating Tables Based on Other Tables

© 2007 by Prentice Hall3-3 Table 3.1 Oracle character data types TypeOracle DesignationDescription FixedCHAR(size)Fixed-length character data of size characters padded with spaces. Maximum size is 2000 bytes. Fixed NationalNCHAR(size)Same as CHAR except stores National characters of maximum length 2000 bytes. VariableVARCHAR2(size)Variable-length character data of size characters. Maximum size is 4000 bytes. Variable NationalNVARCHAR2(size)Variable-length character data of size National characters. Maximum size is 4000 bytes. MemoLONGCharacter data of variable length up to 2 gigabytes. (Not recommended. Use CLOB data type instead.)

© 2007 by Prentice Hall3-4 Table 3.2 Oracle numeric data types TypeOracle DesignationDescription INT, INTEGER, SMALLINTNUMBER(38)An integer with up to 38 digits of precision. Fixed precisionNUMBER(p,s)A variable length number. Precision is the maximum number of digits, scale is the maximum number of digits to the right of the decimal point. FLOAT, DOUBLE PRECISION NUMBERA floating-point number with up to 38 digits of precision.

© 2007 by Prentice Hall3-5 Table 3.3 Oracle date and time data types TypeOracle DesignationDescription INT, INTEGER, SMALLINTNUMBER(38)An integer with up to 38 digits of precision. Fixed precisionNUMBER(p,s)A variable length number. Precision is the maximum number of digits, scale is the maximum number of digits to the right of the decimal point. FLOAT, DOUBLE PRECISION NUMBERA floating-point number with up to 38 digits of precision.

© 2007 by Prentice Hall3-6 Table 3.4 Oracle image data types Oracle DesignationDescription BLOBBinary LOB stores binary, unstructured data up to 128 terabytes. CLOBCharacter LOB stores character data for very large objects—up to 128 terabytes. NCLOBVariable length Unicode national character data up to 128 terabytes.

© 2007 by Prentice Hall3-7 Table 3.5 Customer column names and data types Column name Data typeMaximum length Special conditions CustomerIDIntegerprimary key FirstNameNational, variable length string30not null LastNameNational, variable length string30not null AddressNational, variable length string40 CityNational, variable length string30 StateNational, variable length string20 ZipcodeNational, variable length string20 HomePhoneNational, variable length string20 CellPhoneNational, variable length string20 WorkPhoneNational, variable length string20

© 2007 by Prentice Hall3-8 Table 3.6 Constraint prefixes and example constraint names Constraint TypeConstraint Type PrefixExample Constraint Name CHECKckck_customers_zipcode FOREIGN KEYfkfk_customers_properties NOT NULLnnnn_agents_lastname PRIMARY KEYpkpk_agentid UNIQUEunun_contactreason_description

© 2007 by Prentice Hall3-9 Table 3.7 ContactReason, data types, and constraint Column nameData typeLengthConstraint ContactReasonNVARCHAR215PRIMARY KEY DescriptionNVARCHAR250

© 2007 by Prentice Hall3-10 Table 3.8 Structure of the Agents table Column nameData typeLengthConstraint AgentIDINTEGERPRIMARY KEY FirstNameNVARCHAR230NOT NULL LastNameNVARCHAR230NOT NULL HireDateDATE BirthDateDATE GenderNVARCHAR210Only allowed values are ‘M’ and ‘F’ WorkPhoneNVARCHAR220 CellPhoneNVARCHAR220UNIQUE HomePhoneNVARCHAR220 TitleNVARCHAR220 TaxIDNVARCHAR220 LicenseIDNVARCHAR220 LicenseDateDATE LicenseExpireDATE LicenseStatusIDINTEGER

© 2007 by Prentice Hall3-11 Table 3.9 Selected objects available through data dictionary views ObjectDescription CONS_COLUMNSTable columns having constraints CONSTRAINTSTable constraints INDEXESTable indexes OBJECTSAll database objects SEQUENCESSequences generating unique keys TAB_COLUMNSTable columns. (USER_TAB_COLUMNS are the current user’s columns) TABLESDatabase tables USERSNames of all database users (ALL_USERS) VIEWSDatabase views

© 2007 by Prentice Hall3-12 Table 3.10 Some of the user constraints columns ColumnDescription ownerOwner of the constraint (username). constraint_nameName of the constraint. constraint_typeType: P, R, C, U, V or O. table_nameTable containing the constraint. statusEither ENABLED or DISABLED.

© 2007 by Prentice Hall3-13 Table 3.11 Customer columns and their constraints Column NameData TypeLengthConstraint CustomerIDIntegerPrimary key; default 0 CompanyNameStringVariable up to 50NOT NULL CityStringVariable up to 50NOT NULL NationStringVariable up to 50(none) ContactIDInteger(none) BaseCurrencyStringVariable up to 50(none)

© 2007 by Prentice Hall Representing tables by listing their names and their column names Customers(CustomerID, FirstName, LastName, Address, City, State, Zipcode, HomePhone, CellPhone, WorkPhone) Listings(ListingID, PropertyID, ListingAgentID, SaleStatusID, BeginListDate, EndListDate, AskingPrice) SaleStatus(SaleStatusID, StatusText)

© 2007 by Prentice Hall Simplified initial design of a Customers real estate table Customers(CustomerID, FirstName, LastName, …, PropertyAddress, SqFt, Bedrooms, …) seller informationproperty information

© 2007 by Prentice Hall Attempting to log in with a new user account having no privileges

© 2007 by Prentice Hall Changing another user’s password changing a password to Columbus Logging in and changing the password to a new one

© 2007 by Prentice Hall Removing a user

© 2007 by Prentice Hall Examining selected Oracle data types

© 2007 by Prentice Hall Creating a table using the SQL*Plus interface SQL statement to create Customers table. Oracle built the table this way.

© 2007 by Prentice Hall Creating and displaying a table comment

© 2007 by Prentice Hall Column comment example comment inserted into the State column

© 2007 by Prentice Hall Displaying NOT NULL constraints using the DESCRIBE statement NOT NULL in the Null? column

© 2007 by Prentice Hall Defining a primary key type this SQL command

© 2007 by Prentice Hall Creating the Agents table with constraints

© 2007 by Prentice Hall Designating default values for selected table columns

© 2007 by Prentice Hall Tables with foreign key references to each other

© 2007 by Prentice Hall Adding constraints with the ALTER TABLE statement

© 2007 by Prentice Hall Adding a column to a table newly added ContactDate column

© 2007 by Prentice Hall Dropping a column from a table

© 2007 by Prentice Hall Marking multiple columns unused columns about to be marked “unused”

© 2007 by Prentice Hall Describing the Listings table

© 2007 by Prentice Hall Displaying table names using a data dictionary view names of tables you created

© 2007 by Prentice Hall Some of the columns in the user_tables view

© 2007 by Prentice Hall Displaying details about a table’s columns

© 2007 by Prentice Hall Listing your table constraints

© 2007 by Prentice Hall Reviewing column constraints for the Listings table

© 2007 by Prentice Hall Displaying more complete constraint information

© 2007 by Prentice Hall Seven rows showing schema SYS’ table comments

© 2007 by Prentice Hall DROP TABLE attempt with resulting error message

© 2007 by Prentice Hall Reinstating a previously dropped table

© 2007 by Prentice Hall Creating a table from another table