module 4: data objects. overview tables are the main objects that store data indexes, views, stored...
TRANSCRIPT
Module 4:Data Objects
Overview
Tables are the main objects that store data
Indexes, views, stored programs and other objects are the support structures
Various table types compared based on data organization
Various index types compared
Native and non-native data type support
Block-level storage architecture
Schema Objects – Table
Tables are the primary objects that store data in rows and columns
Each DBMS offers different types of tables to support different access needs with optimal performance and extended functionality as the goals
Oracle SQL Server
Heap-Organized Table Heap
Clustered Table -
Partitioned Table Partitioned Table
Nested Table XML datatype
Temporary Table Temporary Table
External Table Linked Server
Object Table Table Types
Index-organized Table Clustered Index
Table Types in Oracle and SQL Server
Putting Data in the Table
Heap is the default form of data organization in a table, where data is stored in an unordered manner
Allocation units can extend beyond themselves
Oracle’s index organized tables store data in a B-tree structure in primary key order
Oracle and SQL Server offer local and global temporary tables to store transient application data
Compression is necessary
Demonstration 1: Reviewing Large Allocation Units
In this demonstration you will see how to:
Create a query to view allocation units
Determine why multiple results for a single index might be provided.
SQL Server Table Structures
Clustered Index Structure in SQL Server
________________________________________________
Index Rows ________________________________
Previous Next
________________________________________________
Index Rows ________________________________
Previous Next
________________________________________________
Index Rows ________________________________
Previous Next
________________________________________________
Index Rows ________________________________
Previous Next
________________________________________________
Data Rows ________________________________
Previous Next
________________________________________________
Data Rows ________________________________
Previous Next
________________________________________________
Data Rows ________________________________
Previous Next
RootIndid = 1Id
Sysindexes
Root node
Intermediate level
Leaf node / data pages
A-Z
W-ZA-D E-H …
…
DebraAndy Charlie
Indexes
Index Structures in Oracle and SQL ServerIndex scheme Oracle SQL Server
B-tree Unique Yes Yes
B-tree Non-unique Yes Yes
B-tree Composite Yes (32 cols) Yes (16 cols)
B-tree Ascending Yes Yes
B-tree Descending Yes Yes
B-tree Cluster Yes Yes
B-tree Reverse key Yes No
B-tree Key compressed Yes No
B-tree Function-based Yes No
B-tree Index organized table Yes Yes (clustered)
B-tree Partitioned Yes No
Bitmap Yes (30 cols) No1
Bitmap Join Yes No1
Constraints
Constraints are data integrity rules defined on columns of a table to enforce certain business rules
Oracle SQL Server
NOT NULL NOT NULL
UNIQUE UNIQUE
PRIMARY KEY PRIMARY KEY
FOREIGN KEY FOREIGN KEY
DEFAULT DEFAULT
CHECK CHECK
Constraints in Oracle and SQL Server
Triggers
Trigger Types Compared
Feature Oracle SQL ServerDML – INSERT Yes YesDML – UPDATE Column/Row RowDML – DELETE Yes YesTiming – BEFORE Yes Yes (INSTEAD OF)Timing – AFTER Yes YesLevel Row/Statement RowViews – INSTEAD OF Yes YesMultiple triggers per action Yes Yes (first/last
specified)DDL Triggers No YesSingle trigger for multiple actions Yes Yes
Views
Both Oracle and SQL Server offer views based on simple queries involving a single table and complex queries based on multiple tablesIndexed views in SQL Server is the only type of view which actually stores dataOracle and SQL Server offer updatable views with INSTEAD OF triggers and WITH CHECK OPTION constraint
View Type Oracle SQL ServerSimple views Yes YesJoin views Yes YesPartitioned views Yes YesUpdatable views Yes YesInline views Yes YesObject views Yes NoIndexed views No Yes
View Types in Oracle and SQL Server
Number Generation and New Names
ORACLE: Sequence ( 0, 1, 2, 3, 4, ……….
• CREATE SEQUENCE SomeNewNumbers • START WITH 0 INCREMENT BY 1
SQL Server: Identity (0, 1, 2, 3, 4, ………..
• CREATE TABLE ASchema.ATable• ( Id int IDENTITY(0,1),• Information nvarchar(12) )
SQL Server: Global Unique Identifiers ( B2794358-DA6A-DD11-829F-001E685F0BC5…
• CREATE TABLE dbo.Globally_Unique_Data• (guid uniqueidentifier CONSTRAINT Guid_Default DEFAULT NEWSEQUENTIALID() ROWGUIDCOL,
• Employee_Name varchar(60)• CONSTRAINT Guid_PK PRIMARY KEY (guid) );
Either: Synonyms
• CREATE SYNONYM MyProduct FOR TheSchema.TheProduct;
Character-Based Data Types
Character-based data types in Oracle and SQL Server
Oracle SQL ServerData Type Size (bytes) Data Type Number of
CharsSize in bytes
Char 1 to 2000 Char 1 to 8000 1 to 8000 fixed
NChar 1 to 2000 (fewer chars) NChar 1 to 4000 2 to 8000 fixed
Varchar 1 to 4000 Varchar Varchar(max)
1 to 80001 to 231-1
0 to 80000 to 2 GB
NVarchar 1 to 4000 (fewer chars) NVarcharNVarchar(max)
1 to 40001 to 230-1
0 to 80000 to 2 GB
Varchar2 1 to 4000
NVarchar2 1 to 4000 (fewer chars)
LONG 1 to 231 Text, Varchar(max)
1 to 231-1 0 to 2 GB
CLOB 1 to 232 Text, Varchar(max)
1 to 231-1 0 to 2 GB
NCLOB 1 to 232 Ntext, Nvarchar(max)
1 to 230-1 0 to 2 GB
Numeric Data Types
Numeric data types in Oracle and SQL ServerOracle SQL Server
Number(19,0) BigInt
Int or Number(10,0) Int
SmallInt or Number(6,0) SmallInt
Number(3,0) TinyInt
Number(p,0) Decimal(p,s)
Number(p,0) Numeric(p,s)
Float or DoublePrecision or Number(38)
Float
Number(1) Bit
Number(19,4) Money
Number(10,4) SmallMoney
Date and Time Types
Oracle SQL ServerData Type Values Data Type Values
Date Date and time to seconds SmallDateTime Date and time to seconds
DateTime Date and time with fractional seconds to 1/300 or 3.33 milliseconds
Calendar 01/01/1753 AD – 01/06/9999 AD (DMY)
Timestamp (TS)Date and time with fractional
seconds (9 digits)
DateTime2 (DT2) Date and time with fractional seconds (7 digits)
Timestamp with time zone (TSTZ) Like TS with zones
Timestamp with local time zone
(TSLTZ)Like TS with relative zones
to users DateTimeOffset Like DT2 with time zone offsets
Calendar – Julian 01/01/4712 BCE - 12/31/4712 CE
Calendar – Gregorian 01/01/0001 AD – 31/12/9999 AD (DMY)
Daylight Savings Time Support Yes Daylight Savings
Time Support No
DATE Date only – Gregorian
TIME Time only with fractional seconds (7 digits)
Binary Data Types
Oracle SQL Server
BLOB Image, Varbinary(max)
Raw Image, Varbinary(max)
Long Raw Image, Varbinary(max)
BFile Similar to Varbinary(max) Filestream
BLOB/Raw(n) Binary(n)
BLOB/Raw(n) Varbinary(n), Varbinary(max)
Binary data types in Oracle and SQL Server
Demonstration 2: Creating a Table
In this demonstration you will see how to:
Create a table taking advantage of filegroups for different types data structures.
Review the results using SSMS
Non-Native Data Types – Beyond Relational
Kim
Raj
Joe Keith
Robert
Jeff
Spatial Hierarchy
Demonstration 3: Beyond Relational
In this demonstration you will see how to:
Define geometric shapes
Define an organizational structure for a company
Oracle and SQL Server Block-Level Data Organization
Microsoft SQLServer Data Page
Row Offsets
OracleData BlockRow Offsets
Page HeaderData Row 1
Data Row 2
Data Row 3
Free Space
Block Header
Free Space
Data Row 3
Data Row 2
Data Row 13 2 1
1 2 3
Review
Reviewed the types of tables found in Oracle and discussed equivalents in SQL Server for heaps, index organized tables and temporary tables
Discussed the supporting schema objects such as indexes and views
Examined the numeric, character and binary data types
Implementation of user-defined data types in Oracle and SQL Server
Comparison of block-level data storage