Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "© 2007 by Prentice Hall3-1 Introduction to Oracle 10g Chapter 3 Creating, Modifying, Renaming, and Deleting Database Tables James Perry and Gerald Post."— Presentation transcript:

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

2 © 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

3 © 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.)

4 © 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.

5 © 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.

6 © 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.

7 © 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

8 © 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

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

10 © 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

11 © 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

12 © 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.

13 © 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)

14 © 2007 by Prentice Hall3-14 3.1 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)

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

16 © 2007 by Prentice Hall3-16 3.3 Attempting to log in with a new user account having no privileges

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

18 © 2007 by Prentice Hall3-18 3.5 Removing a user

19 © 2007 by Prentice Hall3-19 3.6 Examining selected Oracle data types

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

21 © 2007 by Prentice Hall3-21 3.8 Creating and displaying a table comment

22 © 2007 by Prentice Hall3-22 3.9 Column comment example comment inserted into the State column

23 © 2007 by Prentice Hall3-23 3.10 Displaying NOT NULL constraints using the DESCRIBE statement NOT NULL in the Null? column

24 © 2007 by Prentice Hall3-24 3.11 Defining a primary key type this SQL command

25 © 2007 by Prentice Hall3-25 3.12 Creating the Agents table with constraints

26 © 2007 by Prentice Hall3-26 3.13 Designating default values for selected table columns

27 © 2007 by Prentice Hall3-27 3.14 Tables with foreign key references to each other

28 © 2007 by Prentice Hall3-28 3.15 Adding constraints with the ALTER TABLE statement

29 © 2007 by Prentice Hall3-29 3.16 Adding a column to a table newly added ContactDate column

30 © 2007 by Prentice Hall3-30 3.17 Dropping a column from a table

31 © 2007 by Prentice Hall3-31 3.18 Marking multiple columns unused columns about to be marked “unused”

32 © 2007 by Prentice Hall3-32 3.19 Describing the Listings table

33 © 2007 by Prentice Hall3-33 3.20 Displaying table names using a data dictionary view names of tables you created

34 © 2007 by Prentice Hall3-34 3.21 Some of the columns in the user_tables view

35 © 2007 by Prentice Hall3-35 3.22 Displaying details about a table’s columns

36 © 2007 by Prentice Hall3-36 3.23 Listing your table constraints

37 © 2007 by Prentice Hall3-37 3.24 Reviewing column constraints for the Listings table

38 © 2007 by Prentice Hall3-38 3.25 Displaying more complete constraint information

39 © 2007 by Prentice Hall3-39 3.26 Seven rows showing schema SYS’ table comments

40 © 2007 by Prentice Hall3-40 3.27 DROP TABLE attempt with resulting error message

41 © 2007 by Prentice Hall3-41 3.28 Reinstating a previously dropped table

42 © 2007 by Prentice Hall3-42 3.29 Creating a table from another table


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

Similar presentations


Ads by Google