Presentation is loading. Please wait.

Presentation is loading. Please wait.

7 Copyright © 2004, Oracle. All rights reserved. Managing Schema Objects.

Similar presentations


Presentation on theme: "7 Copyright © 2004, Oracle. All rights reserved. Managing Schema Objects."— Presentation transcript:

1 7 Copyright © 2004, Oracle. All rights reserved. Managing Schema Objects

2 7-2 Copyright © 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Compare schema objects and data types Create and modify tables Define constraints View the columns in a table View the contents of a table Create indexes and views Compare the use of temporary tables

3 7-3 Copyright © 2004, Oracle. All rights reserved. What Is a Schema? HR schema HR user owns

4 7-4 Copyright © 2004, Oracle. All rights reserved. Schemas Schemas created as part of the database creation process: SYS SYSTEM Sample schemas

5 7-5 Copyright © 2004, Oracle. All rights reserved. Schemas - Full Notes Page

6 7-6 Copyright © 2004, Oracle. All rights reserved. Accessing Schema Objects Click a link to access the schema objects.

7 7-7 Copyright © 2004, Oracle. All rights reserved. Oracle Database and SQL Server: Similarities Similar schema objects (tables, views) Similar data types Referential integrity Check constraints/rules Transaction support Triggers and stored subprograms SQL access to system catalog (data dictionary)

8 7-8 Copyright © 2004, Oracle. All rights reserved. Comparing Schema Objects Oracle schema objects not available in SQL Server: –Database link (SQL Server: stored procedure) –Profile –Materialized view –Sequence (SQL Server: Serial data type) –Synonym SQL Server rule, integrity, and default are implemented as constraints of Oracle tables.

9 7-9 Copyright © 2004, Oracle. All rights reserved. Naming Database Objects Names must be from 1 to 30 bytes long with these exceptions: –Names of databases are limited to 8 bytes. –Names of database links can be as long as 128 bytes. Nonquoted names cannot be Oracle-reserved words. Nonquoted names must begin with an alphabetic character from your database character set.

10 7-10 Copyright © 2004, Oracle. All rights reserved. Naming Database Objects Nonquoted names can contain only: –Alphanumeric characters from your database character set –The underscore (_) –Dollar sign ($) –Pound sign (#) No two objects can have the same name within the same namespace. MS Tip: OMWB assists with resolving naming conflicts.

11 7-11 Copyright © 2004, Oracle. All rights reserved. Schema Object Namespaces The following have their own namespace: Indexes Constraints Clusters Database triggers Private database links Dimensions The following are in the same namespace: Tables Views Sequences Private synonyms Stand-alone procedures Stand-alone stored functions Packages Materialized views User-defined types

12 7-12 Copyright © 2004, Oracle. All rights reserved. Specifying Data Types in Tables Common data types: CHAR(size) : Fixed-length character data of length size bytes VARCHAR2(size) : Variable-length character string having maximum length size bytes DATE : Valid date range from January 1, 4712 B.C. to A.D. December 31, 9999 NUMBER(p,s) : Number having precision p and scale s

13 7-13 Copyright © 2004, Oracle. All rights reserved. Other Data Types BINARY_FLOAT BINARY_DOUBLE FLOAT INTEGER NCHAR NVARCHAR2 LONG LONG RAW RAW ROWID UROWID BLOB CLOB NCLOB BFILE TIMESTAMP

14 7-14 Copyright © 2004, Oracle. All rights reserved. Other Data Types Full Notes Page

15 7-15 Copyright © 2004, Oracle. All rights reserved. Comparing Data Types SQL ServerOracle INTEGERNUMBER(10) SMALLINTNUMBER(6) TINYINTNUMBER(3) DECIMAL(p,[q])NUMBER(p,[q]) NUMERIC(p,[q])NUMBER(p,[q]) REALFLOAT FLOAT[(p)] BITNUMBER(1) CHAR(n) VARCHAR(n)VARCHAR2(n) NCHAR(n)CHAR(n*2) NVARCHAR(n)VARCHAR(n*2)

16 7-16 Copyright © 2004, Oracle. All rights reserved. Comparing Data Types SQL ServerOracle TEXTCLOB IMAGEBLOB BINARY(n)RAW(n), BLOB VARBINARY(n)RAW(n), BLOB DATETIMEDATE (or TIMESTAMP) SMALLDATETIMEDATE (with constraint) MONEYNUMBER(19,4) SMALLMONEYNUMBER(10,4) TIMESTAMPNUMBER SYSNAMEVARCHAR2(30)

17 7-17 Copyright © 2004, Oracle. All rights reserved. Creating and Modifying Tables Specify the table name and schema. Specify the column names, data types, and lengths.

18 7-18 Copyright © 2004, Oracle. All rights reserved. Creating and Modifying Tables Full Notes Page

19 7-19 Copyright © 2004, Oracle. All rights reserved. Understanding Data Integrity

20 7-20 Copyright © 2004, Oracle. All rights reserved. Understanding Data Integrity Full Notes Page

21 7-21 Copyright © 2004, Oracle. All rights reserved. Constraint States ENABLE NOVALIDATE ENABLE VALIDATE Existing dataNew data DISABLE NOVALIDATE DISABLE VALIDATE No DML

22 7-22 Copyright © 2004, Oracle. All rights reserved. Defining Constraints

23 7-23 Copyright © 2004, Oracle. All rights reserved. Constraint Checking DML statement, followed by: COMMIT ; Check nondeferred constraints COMMIT issued Check deferred constraints COMMIT complete

24 7-24 Copyright © 2004, Oracle. All rights reserved. Viewing the Columns in a Table

25 7-25 Copyright © 2004, Oracle. All rights reserved. Viewing the Contents of a Table

26 7-26 Copyright © 2004, Oracle. All rights reserved. Actions with Tables

27 7-27 Copyright © 2004, Oracle. All rights reserved. Actions with Tables Full Notes Page

28 7-28 Copyright © 2004, Oracle. All rights reserved. Creating Indexes

29 7-29 Copyright © 2004, Oracle. All rights reserved. What Is a View? A view is a customized representation of data in a table or view. Views do not contain data.

30 7-30 Copyright © 2004, Oracle. All rights reserved. Creating Views

31 7-31 Copyright © 2004, Oracle. All rights reserved. What Is a Sequence? Generating primary key values SQL Server: Serial data type Oracle: Sequence plus database trigger

32 7-32 Copyright © 2004, Oracle. All rights reserved. What Is a Sequence? Full Notes Page

33 7-33 Copyright © 2004, Oracle. All rights reserved. Using a Sequence

34 7-34 Copyright © 2004, Oracle. All rights reserved. Deleting a Table Dropping a table removes: Data Table structure Database triggers Corresponding indexes Associated object privileges Optional clauses for the DROP TABLE statement: CASCADE CONSTRAINTS: Dependant referential integrity constraints PURGE: No flashback possible DROP TABLE hr.employees PURGE ;

35 7-35 Copyright © 2004, Oracle. All rights reserved. Truncating a Table Truncating a table deletes all rows in a table and releases used space. Corresponding indexes are truncated. TRUNCATE TABLE hr.employees;

36 7-36 Copyright © 2004, Oracle. All rights reserved. Migration Considerations: Temporary Tables SQL Server: –Local temporary tables, names beginning with # –Global temporary tables, names beginning with ## –Not compatible with Oracle’s naming conventions Options in Oracle: –Temporary ANSI-style (global temporary) tables –Multitable joins (optimized internally) –Materialized views –PL/SQL tables

37 7-37 Copyright © 2004, Oracle. All rights reserved. Full Notes Page

38 7-38 Copyright © 2004, Oracle. All rights reserved. Creating Temporary Tables Use the GLOBAL TEMPORARY clause to create temporary tables. Tables retain data only for the duration of a transaction or session. DML locks are not acquired on the data. You can create indexes, views, and triggers on temporary tables. CREATE GLOBAL TEMPORARY TABLE hr.employees_temp AS SELECT * FROM hr.employees;

39 7-39 Copyright © 2004, Oracle. All rights reserved. Summary In this lesson, you should have learned how to: Compare schema objects and data types Create and modify tables Define constraints View the columns in a table View the contents of a table Create indexes Compare the use of temporary tables

40 7-40 Copyright © 2004, Oracle. All rights reserved. Practice Overview: Administering Schema Objects This practice covers the following topics: Creating tables with columns Creating constraints: –Primary key –Check –Foreign key Creating indexes


Download ppt "7 Copyright © 2004, Oracle. All rights reserved. Managing Schema Objects."

Similar presentations


Ads by Google