1 Introduction to Domains A line manager asks, “If a domain is a kingdom in the middle ages; what...

34
1 Introduction to Introduction to Domains Domains A line manager asks, A line manager asks, “If a domain is a kingdom “If a domain is a kingdom in the middle ages; what do our consultants mean in the middle ages; what do our consultants mean when they say it’s the domain of this or that in the when they say it’s the domain of this or that in the database – by the way do you think a domain is like database – by the way do you think a domain is like that Abott & Costello comedy routine, who’s on first that Abott & Costello comedy routine, who’s on first base.” base.”

Transcript of 1 Introduction to Domains A line manager asks, “If a domain is a kingdom in the middle ages; what...

11

Introduction to DomainsIntroduction to Domains

A line manager asks, A line manager asks, “If a domain is a kingdom “If a domain is a kingdom in the middle ages; what do our consultants in the middle ages; what do our consultants

mean when they say it’s the domain of this or mean when they say it’s the domain of this or that in the database – by the way do you think a that in the database – by the way do you think a

domain is like that Abott & Costello comedy domain is like that Abott & Costello comedy routine, who’s on first base.”routine, who’s on first base.”

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 22

Introduction to DomainsIntroduction to Domains

Domains & domain analysisDomains & domain analysis Using domainsUsing domains Importance of domainsImportance of domains Domain of modelsDomain of models

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 33

Domains & domain analysisDomains & domain analysis

Domain of a column data typeDomain of a column data type Domain of a structure or rowDomain of a structure or row Domain of a set of structures (rows)Domain of a set of structures (rows) Domain of sets of structures (rows)Domain of sets of structures (rows) Domain of position & signatureDomain of position & signature

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 44

Domain of a column data Domain of a column data typetype

Defining domain rangesDefining domain ranges Assigning data types to columnsAssigning data types to columns Defining strong data typesDefining strong data types ANSI SQL:2003 data typesANSI SQL:2003 data types Defining user-defined data typesDefining user-defined data types Managing physical sizesManaging physical sizes

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 55

Defining domain rangesDefining domain ranges

Rule #1:Rule #1: A domain range sets the lowest and highest values for some A domain range sets the lowest and highest values for some

data types, like an int, double, or float.data types, like an int, double, or float. Rule #2:Rule #2:

A domain range can be a set of values or a subset of values, A domain range can be a set of values or a subset of values, like a like a NUMBERNUMBER data type is a type while its derived data type is a type while its derived specialization a specialization a FLOATFLOAT data type is a subtype of data type is a subtype of NUMBERNUMBER, at , at least in an Oracle database.least in an Oracle database.

Rule #3:Rule #3: A domain range can set both maximum length and character A domain range can set both maximum length and character

set limits, like variable length strings.set limits, like variable length strings. Rule #4:Rule #4:

A domain range can statically define or dynamically allot a A domain range can statically define or dynamically allot a physical length and/or range of character values, like ASCII physical length and/or range of character values, like ASCII character values that map to English alphabetical characters. character values that map to English alphabetical characters.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 66

Assigning data types to Assigning data types to columnscolumns

Rule #1:Rule #1: A column can have only one data type at any moment in time, and the A column can have only one data type at any moment in time, and the

data type is assigned when you create the column in a table.data type is assigned when you create the column in a table. Rule #2:Rule #2:

A column can have its data type changed by using the A column can have its data type changed by using the ALTERALTER command command on an existing table, provided it doesn’t contain data.on an existing table, provided it doesn’t contain data.

Rule #3:Rule #3: A column can sometimes have its data type changed by using the A column can sometimes have its data type changed by using the ALTERALTER

command on an existing table, provided the database knows how to command on an existing table, provided the database knows how to implicitly cast from one data type to another.implicitly cast from one data type to another.

Rule #4:Rule #4: A column can only contain values consistent with its assigned data type, A column can only contain values consistent with its assigned data type,

or it is considered a multiple-part value, like a comma-separated-file.or it is considered a multiple-part value, like a comma-separated-file. Rule #5:Rule #5:

A column Can contain a A column Can contain a nullnull or or not nullnot null value for numeric types and a value for numeric types and a nullnull, , emptyempty and and populatedpopulated value for strings and large object types, like value for strings and large object types, like how a string column can have a null, zero length string, or non-zero how a string column can have a null, zero length string, or non-zero length string.length string.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 77

Defining strong data typesDefining strong data types

Rule #1:Rule #1: A data type has a defined domain, or range of values.A data type has a defined domain, or range of values.

Rule #2:Rule #2: A data type id assigned to a column, and the database A data type id assigned to a column, and the database

disallows entry of anything not conforming to the data type.disallows entry of anything not conforming to the data type. Rule #3:Rule #3:

A data type is only one thing, or a collection of things, but the A data type is only one thing, or a collection of things, but the thing or collection of things must be defined.thing or collection of things must be defined.

Rule #4:Rule #4: A data type does not change at runtime but can be altered by A data type does not change at runtime but can be altered by

routine database maintenance using an routine database maintenance using an ALTERALTER DDL statement. DDL statement. Rule #5:Rule #5:

A data type is cataloged by the database and rules are A data type is cataloged by the database and rules are enforced as operational constraints.enforced as operational constraints.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 88

Defining ANSI SQL:2003 data Defining ANSI SQL:2003 data typestypes

Rule #1:Rule #1: Generic data types can have implementation specific names, and these differ Generic data types can have implementation specific names, and these differ

between commercial products.between commercial products. Rule #2:Rule #2:

Boolean, number, date and timestamp data types are scalar variables, which Boolean, number, date and timestamp data types are scalar variables, which means they can only hold one thing at any point in time; they are also known as means they can only hold one thing at any point in time; they are also known as primitive variables in the Java programming language.primitive variables in the Java programming language.

Rule #3:Rule #3: Strings, collections and large object files can hold more than one value at any Strings, collections and large object files can hold more than one value at any

point in time, they are point in time, they are compoundcompound or or compositecomposite variables dependent on various variables dependent on various labeling approaches.labeling approaches.

Rule #4:Rule #4: Column values of scalar data types are null by default unless you have Column values of scalar data types are null by default unless you have

designated a not null database constraint.designated a not null database constraint. Rule #5:Rule #5:

Column values of compound data types are null by default but can be initialized Column values of compound data types are null by default but can be initialized as empty or populated values, unless you have designated a not null database as empty or populated values, unless you have designated a not null database constraint that makes them empty or populated.constraint that makes them empty or populated.

Rule #6:Rule #6: Column values can have a default value assigned when the tables is created or Column values can have a default value assigned when the tables is created or

altered but you can only use scalar values or string literals as default values altered but you can only use scalar values or string literals as default values typically.typically.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 99

Defining user-defined data Defining user-defined data typestypes

Rule #1:Rule #1: Define compound data types that are product specific and vary Define compound data types that are product specific and vary

greatly as to implementation details.greatly as to implementation details. Rule #2:Rule #2:

Define incomplete types, object types, structures, or repeating Define incomplete types, object types, structures, or repeating structures according to the ANSI SQL:2003 specification. structures according to the ANSI SQL:2003 specification. Incomplete data types are like using forward referencing in a Incomplete data types are like using forward referencing in a single pass compiler or interpreter.single pass compiler or interpreter.

Rule #3:Rule #3: Support compound structures, like varrays and nested tables Support compound structures, like varrays and nested tables

introduced in the ANSI SQL:1999 specification.introduced in the ANSI SQL:1999 specification. Rule #4:Rule #4:

Support compound structures, like objects written in external Support compound structures, like objects written in external languages, like Java, C++ and C#, or proprietary languages languages, like Java, C++ and C#, or proprietary languages like Oracle PL/SQL.like Oracle PL/SQL.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 1010

Physical size managementPhysical size management

Rule #1:Rule #1: Data type physical size is operating system specific and Data type physical size is operating system specific and

platform dependent.platform dependent. Rule #2:Rule #2:

Data type physical size is product implementation specific.Data type physical size is product implementation specific. Rule #3:Rule #3:

Data type physical size is encapsulated from the SQL Data type physical size is encapsulated from the SQL developer and developer and not alterablenot alterable..

Rule #4:Rule #4: Data type physical size is defined and stored in the Data type physical size is defined and stored in the

database catalog, that contains metadata (or, data about database catalog, that contains metadata (or, data about data).data).

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 1111

Domains of a structure or Domains of a structure or rowrow

Defining structures or rowsDefining structures or rows Defining key and non-key columnsDefining key and non-key columns Defining primary keysDefining primary keys Defining superkeysDefining superkeys Defining foreign keysDefining foreign keys Defining integrity constraintsDefining integrity constraints

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 1212

Defining a structure or rowDefining a structure or row

Rule #1:Rule #1: A row is a record structure, defined by a list of fields that are described A row is a record structure, defined by a list of fields that are described

by data types, like a structure in traditional programming languages.by data types, like a structure in traditional programming languages. Rule #2:Rule #2:

A row is a compound variable, which is variable that contains more A row is a compound variable, which is variable that contains more than one thing at any moment in time.than one thing at any moment in time.

Rule #3:Rule #3: A row is a 1-Dimensional array indexed by a column name, which A row is a 1-Dimensional array indexed by a column name, which

actually maps in the catalog to a positional number and name.actually maps in the catalog to a positional number and name. Rule #4:Rule #4:

A collection of rows, or record structures, is known as an array of A collection of rows, or record structures, is known as an array of structures, a collection or a database table.structures, a collection or a database table.

Rule #5:Rule #5: A row is interchangeably described by fields, attributes or columns A row is interchangeably described by fields, attributes or columns

because they’re synonymous in database vocabulary. These because they’re synonymous in database vocabulary. These descriptors are 1-Dimensional array indexes, and they are used to descriptors are 1-Dimensional array indexes, and they are used to project through fields in a collection of records, which is a longhand project through fields in a collection of records, which is a longhand way of describing a table.way of describing a table.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 1313

Defining key and non-key Defining key and non-key columnscolumns

Rule #1:Rule #1: A column should only contain a descriptive element of a record.A column should only contain a descriptive element of a record.

Rule #2:Rule #2: A column describes something about a row of information.A column describes something about a row of information.

Rule #3:Rule #3: A column can contain a sequence value to identify unique rows A column can contain a sequence value to identify unique rows

in a table, which is called a surrogate key and otherwise not in a table, which is called a surrogate key and otherwise not descriptive of the problem.descriptive of the problem.

Rule #4:Rule #4: A A keykey column can be used alone or together with one or more column can be used alone or together with one or more

columns to find a specific row, or set of rows through selection columns to find a specific row, or set of rows through selection or projection.or projection.

Rule #5:Rule #5: A A non-keynon-key column cannot be used alone or together with one column cannot be used alone or together with one

or more columns to find a specific row.or more columns to find a specific row.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 1414

Defining primary keysDefining primary keys

Rule #1:Rule #1: A A primary keyprimary key column should identify a unique row in a collection or a column should identify a unique row in a collection or a

database table.database table. Rule #2:Rule #2:

A A primary keyprimary key can contain one to many columns but it must define can contain one to many columns but it must define uniqueness for any row in a table.uniqueness for any row in a table.

Rule #3:Rule #3: A A primary keyprimary key is both unique and not null constrained by definition, is both unique and not null constrained by definition,

this can apply to one column or a group columns that act collectively this can apply to one column or a group columns that act collectively as a primary key.as a primary key.

Rule #4:Rule #4: A A primary-keyprimary-key can be borrowed by dependent tables as a foreign key can be borrowed by dependent tables as a foreign key

value, which enables you to define a relationship between tables.value, which enables you to define a relationship between tables. Rule #5:Rule #5:

A A primary-keyprimary-key can be borrowed by the same table as a foreign key can be borrowed by the same table as a foreign key value to support a recursive relationship, which enables you to define value to support a recursive relationship, which enables you to define an internal relationship between rows in the same table.an internal relationship between rows in the same table.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 1515

Definig superkeysDefinig superkeys

Rule #1:Rule #1: A A superkeysuperkey column should identify a unique row in a column should identify a unique row in a

collection or a database table through an internal or external collection or a database table through an internal or external relationship.relationship.

Rule #2:Rule #2: A A superkeysuperkey can contain one to many columns but it must can contain one to many columns but it must

define uniqueness for any row in a table in the context of a define uniqueness for any row in a table in the context of a relationship.relationship.

Rule #3:Rule #3: A A superkeysuperkey is not necessarily unique or not null constrained is not necessarily unique or not null constrained

by definition, the constraints for a multiple column superkey by definition, the constraints for a multiple column superkey can vary between columns.can vary between columns.

Rule #4:Rule #4: A A superkeysuperkey can be borrowed by the same table or a can be borrowed by the same table or a

dependent tables as a filtering column value (typically dependent tables as a filtering column value (typically deployed in a deployed in a WHEREWHERE clause), like a GENDER column. clause), like a GENDER column.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 1616

Defining foreign keyDefining foreign key

Rule #1:Rule #1: A A foreign keyforeign key column points to a primary key in the same or another column points to a primary key in the same or another

table.table. Rule #2:Rule #2:

A A foreign keyforeign key can contain one to many columns but must map to a can contain one to many columns but must map to a valid primary key in the same or another table.valid primary key in the same or another table.

Rule #3:Rule #3: A A foreign keyforeign key can be unique or non-unique but should be not null can be unique or non-unique but should be not null

constrained by definition because primary keys are so constrained.constrained by definition because primary keys are so constrained. Rule #4:Rule #4:

A A foreign keyforeign key supports a join between the table by mapping the supports a join between the table by mapping the foreign key value to a primary key value in the same or another table.foreign key value to a primary key value in the same or another table.

Rule #5:Rule #5: When When Foreign keyForeign key columns are borrowed from the same table, you columns are borrowed from the same table, you

have a recursive relationship, which enables you to define an internal have a recursive relationship, which enables you to define an internal relationship between rows in the same table.relationship between rows in the same table.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 1717

Defining integrity Defining integrity constraintsconstraints

Unique:Unique: A A uniqueunique constraint tells the database to disallow a column to hold two or more constraint tells the database to disallow a column to hold two or more

equal values, and typically made using “out-of-line” constraint syntax.equal values, and typically made using “out-of-line” constraint syntax. Not nullNot null::

A A not nullnot null constraint tells the database to disallow entry of a null value into the constraint tells the database to disallow entry of a null value into the column from an column from an INSERTINSERT or or UPDATEUPDATE statement, a not null constraint must be made statement, a not null constraint must be made using using “inline”“inline” syntax or it is a syntax or it is a checkcheck constraint. constraint.

Check:Check: A A checkcheck constraint tells the database to disallow entry or update of a column constraint tells the database to disallow entry or update of a column

value that fails to meet the expression governing the constraint, and typically value that fails to meet the expression governing the constraint, and typically made using “out of line” constraint syntax.made using “out of line” constraint syntax.

Primary key:Primary key: A A primaryprimary key tells the database to allow entry or update of a column value that key tells the database to allow entry or update of a column value that

is only both unique and not null, and it enables a foreign key constraint to is only both unique and not null, and it enables a foreign key constraint to reference the column or set of columns defined as the primary key, and typically reference the column or set of columns defined as the primary key, and typically made using “out-of-line” constraint syntax.made using “out-of-line” constraint syntax.

Foreign key:Foreign key: A A foreignforeign key constraint tells the database to disallow entry or update of a key constraint tells the database to disallow entry or update of a

column value that is not found in the referenced primary key column list of column value that is not found in the referenced primary key column list of values, and typically made using “out-of-line” constraint syntax.values, and typically made using “out-of-line” constraint syntax.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 1818

Domains of a set of structures Domains of a set of structures (rows)(rows)

Defining relational algebraic Defining relational algebraic selectionsselections

Defining relational algebraic Defining relational algebraic projectionsprojections

Defining multiple-valued columnsDefining multiple-valued columns Defining natural keysDefining natural keys Defining surrogate keysDefining surrogate keys

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 1919

Defining relational algebraic Defining relational algebraic selectionsselections

Rule #1:Rule #1: The process of accessing a row as a structure or unit from a 2-dimensional The process of accessing a row as a structure or unit from a 2-dimensional

structure is known as structure is known as selectionselection, and it uses the index of the outermost array., and it uses the index of the outermost array. Rule #2:Rule #2:

The The selectionselection process uses a primary key value as the index, which can be either process uses a primary key value as the index, which can be either a natural key (composed of descriptive attributes), or a surrogate key (composed a natural key (composed of descriptive attributes), or a surrogate key (composed of an artificial numeric index).of an artificial numeric index).

Rule #3:Rule #3: The The physical selectionphysical selection process is typically hidden and uses an internal key that process is typically hidden and uses an internal key that

typically maps through the database catalog to a physical disk block address, typically maps through the database catalog to a physical disk block address, which in Oracle databases is the pseudo column which in Oracle databases is the pseudo column ROWIDROWID..

Rule #4:Rule #4: The selection process occur as a row-by-row fetch, unless a database The selection process occur as a row-by-row fetch, unless a database

implementation supports bulk fetches, like Oracle 9i forward, and returns a 2-implementation supports bulk fetches, like Oracle 9i forward, and returns a 2-dimensional array dimensional array result setresult set..

Rule #5:Rule #5: The The selectionselection process filters a result set by using the process filters a result set by using the WHEREWHERE clause in DQL and clause in DQL and

DML statements, filtering is an example of relational algebraic DML statements, filtering is an example of relational algebraic projectionprojection..

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 2020

Defining relational algebraic Defining relational algebraic projectionsprojections

Rule #1:Rule #1: The process of accessing a set of rows by a column name in a 2-The process of accessing a set of rows by a column name in a 2-

dimensional structure like a table is known as dimensional structure like a table is known as projectionprojection because you because you project across rows using an inner array column name.project across rows using an inner array column name.

Rule #2:Rule #2: The The projectionprojection process relies on a column name as a key value, which process relies on a column name as a key value, which

works in databases because all rows are symmetrical, or clones of the works in databases because all rows are symmetrical, or clones of the same structure, with null values substituted for missing values.same structure, with null values substituted for missing values.

Rule #3:Rule #3: The The physical projectionphysical projection process depends on the outermost array, or process depends on the outermost array, or

row, selection process, and there is no bulk fetch process to avoid a row, selection process, and there is no bulk fetch process to avoid a row-by-row row-by-row fetchingfetching of records into the result set. of records into the result set.

Rule #4:Rule #4: The The projectionprojection process works concurrently against multiple columns. process works concurrently against multiple columns.

Rule #5:Rule #5: The The projectionprojection process filters by using the process filters by using the WHEREWHERE clause in DQL and clause in DQL and

DML statements. DML statements.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 2121

Defining multiple valued Defining multiple valued columnscolumns

Rule #1:Rule #1: Multiple valued columns are typically not included in a natural key Multiple valued columns are typically not included in a natural key

because they compromise the efficiency of the selection process.because they compromise the efficiency of the selection process. Rule #2:Rule #2:

Multiple valued columns are typically non-unique values in a column.Multiple valued columns are typically non-unique values in a column. Rule #3:Rule #3:

Multiple valued columns are helpful to support projection operations Multiple valued columns are helpful to support projection operations looking for common subsets in a set of data, like all males or females in looking for common subsets in a set of data, like all males or females in a table with a GENDER column.a table with a GENDER column.

Rule #4:Rule #4: Multiple valued columns in a natural key indicate the domain of the Multiple valued columns in a natural key indicate the domain of the

table is poorly defined.table is poorly defined. Rule #5:Rule #5:

Multiple valued columns in a natural key seriously degrade the Multiple valued columns in a natural key seriously degrade the efficiency of all join operations when they exceed 15% of all rows and efficiency of all join operations when they exceed 15% of all rows and may require a full table read after a full index read.may require a full table read after a full index read.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 2222

Defining natural keysDefining natural keys

Rule #1:Rule #1: A natural key is defined by one or more columns that are both A natural key is defined by one or more columns that are both

unique and not null in the data set stored in a table.unique and not null in the data set stored in a table. Rule #2:Rule #2:

A natural key represents the model of uniqueness at the time A natural key represents the model of uniqueness at the time of design and can change as more knowledge is developed of design and can change as more knowledge is developed about the business problem.about the business problem.

Rule #3:Rule #3: A natural key composed of more than one column is an ideal A natural key composed of more than one column is an ideal

index, which speeds the selection process because you can index, which speeds the selection process because you can project through the index hash.project through the index hash.

Rule #4:Rule #4: A natural key does modify occasionally and should not be used A natural key does modify occasionally and should not be used

as a primary key because when it changes, you will have to as a primary key because when it changes, you will have to rewrite all SQL statement joins – prohibitively risky and rewrite all SQL statement joins – prohibitively risky and expensive.expensive.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 2323

Defining surrogate keysDefining surrogate keys

Rule #1:Rule #1: A surrogate key is defined as a unique numeric index value, A surrogate key is defined as a unique numeric index value,

like the index in a standard programming array.like the index in a standard programming array. Rule #2:Rule #2:

A surrogate key is also known in some products as automatic A surrogate key is also known in some products as automatic numbering.numbering.

Rule #3:Rule #3: A surrogate key is supported by a database A surrogate key is supported by a database SEQUENCESEQUENCE

structure, which is accessible in some database products and structure, which is accessible in some database products and not accessible in others.not accessible in others.

Rule #4:Rule #4: A surrogate key defines nothing in the domain of the data.A surrogate key defines nothing in the domain of the data.

Rule #5:Rule #5: A surrogate key defines unique rows in the domain of the A surrogate key defines unique rows in the domain of the

table.table.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 2424

Domains of sets of structures Domains of sets of structures (rows)(rows)

Defining sets of structuresDefining sets of structures When you merge columns from multiple tables you create When you merge columns from multiple tables you create

rows of a merged set of structures, two or more tables.rows of a merged set of structures, two or more tables. The full set of columns from one table is a result set of a The full set of columns from one table is a result set of a

structure, while the combination of two or more partial or structure, while the combination of two or more partial or full sets of structures is a merged result set and a new full sets of structures is a merged result set and a new structure.structure.

Result sets are composed of a superset of data drawn from Result sets are composed of a superset of data drawn from all or part of columns from two or more tables.all or part of columns from two or more tables.

The common column value between structures is the The common column value between structures is the primary key in one table and foreign key in other, generally primary key in one table and foreign key in other, generally it is excluded from a merged result set or only one copy is it is excluded from a merged result set or only one copy is found.found.

Primary and foreign key values typically only serve to Primary and foreign key values typically only serve to merge tables and are not used in merged result sets when merge tables and are not used in merged result sets when they are surrogate primary keys.they are surrogate primary keys.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 2525

Domains of position and signatureDomains of position and signature

Defining signaturesDefining signatures A signature is often described as a prototype for a A signature is often described as a prototype for a

function or method in programming languages.function or method in programming languages. Database tables are defined at their creation with Database tables are defined at their creation with

column names that have column types, and the columns column names that have column types, and the columns are stored in the are stored in the database catalogdatabase catalog in the order that they in the order that they are listed in the are listed in the CREATECREATE statement. statement.

SQL has always supported both positional and named SQL has always supported both positional and named INSERTINSERT statements, the default signature is by position. statements, the default signature is by position.

You override positional signatures by providing an You override positional signatures by providing an overriding signature, which uses the column names to overriding signature, which uses the column names to replace the positional ordering.replace the positional ordering.

All All UPDATEUPDATE statements use column names to set values, statements use column names to set values, therefore, only the therefore, only the INSERTINSERT statement imposes a default statement imposes a default signature.signature.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 2626

Using domainsUsing domains

Data typesData types A data type must have an understood range of values.A data type must have an understood range of values. A data type must be scalar or compound, the latter are data structures or A data type must be scalar or compound, the latter are data structures or

objects in an Object Relational Database Management System like Oracle.objects in an Object Relational Database Management System like Oracle. Data structuresData structures

A data structure, or table definition, requires a definition, and the A data structure, or table definition, requires a definition, and the definition sets the list of scalar variables, which then set their field definition sets the list of scalar variables, which then set their field element data types and respective ranges.element data types and respective ranges.

A data structure, or table definition, can contain a compound variable like A data structure, or table definition, can contain a compound variable like a collection of scalar or compound data types, examples of nesting tables. a collection of scalar or compound data types, examples of nesting tables.

User account or User account or schemaschema A work area that contains delegated rights and privileges.A work area that contains delegated rights and privileges. A work area that contains user database objects.A work area that contains user database objects.

Database CatalogDatabase Catalog A set of structures, or tables, that contain the operating definitions of the A set of structures, or tables, that contain the operating definitions of the

database management system, like data types.database management system, like data types. A set of structures that are dynamic as users work in the database.A set of structures that are dynamic as users work in the database.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 2727

Importance of domainsImportance of domains

Defining the operating normsDefining the operating norms The domain of data types provide a context to what is defined, The domain of data types provide a context to what is defined,

how it works, and whether a data type can be extended.how it works, and whether a data type can be extended. The domain of data types must be known for a database The domain of data types must be known for a database

management system to work with a data type because it must management system to work with a data type because it must know how to work with the type in memory and disk storage.know how to work with the type in memory and disk storage.

The domain of data types determines how you access types The domain of data types determines how you access types using SQL.using SQL.

Defining the operating environmentDefining the operating environment The domain of a data structure qualifies how data elements are The domain of a data structure qualifies how data elements are

organized, and what defines the field data types.organized, and what defines the field data types. The domain of accounts defines how accounts work.The domain of accounts defines how accounts work. The domain of grants and privileges defines how user accounts The domain of grants and privileges defines how user accounts

work with each other.work with each other. The domain of the database catalog keeps track of everything The domain of the database catalog keeps track of everything

and makes sure it conforms to the database management and makes sure it conforms to the database management system rules.system rules.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 2828

Domains & domain analysisDomains & domain analysis

Domain as a columnDomain as a column Domain as a tableDomain as a table Domain as a relationDomain as a relation Domain as a user/schemaDomain as a user/schema Domain as a modelDomain as a model

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 2929

Domain as a columnDomain as a column

A column has only one data type, which A column has only one data type, which can be a scalar or compound type.can be a scalar or compound type.

A column with a scalar type can hold A column with a scalar type can hold only one thing at any moment in time..only one thing at any moment in time..

A column with a compound type can A column with a compound type can require special handling in SQL and may require special handling in SQL and may contain a list of like things, or a contain a list of like things, or a structure or nested table.structure or nested table.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 3030

Domain as a tableDomain as a table

A table contains a list of column names A table contains a list of column names identified by data type, Oracle supports identified by data type, Oracle supports 999 columns in a table.999 columns in a table.

A table contains rows of data that A table contains rows of data that contain values for some or all defining contain values for some or all defining columns.columns.

A table contains zero to many rows, A table contains zero to many rows, there is virtually no limit on the number there is virtually no limit on the number of rows.of rows.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 3131

Domain as a relationDomain as a relation

A relation can be between two rows in one A relation can be between two rows in one table.table.

A relation can be between one row in one A relation can be between one row in one table and one row in another table.table and one row in another table.

A relation can be between one row in one A relation can be between one row in one table and many rows in another table.table and many rows in another table.

A relation is only stored in the catalog A relation is only stored in the catalog when it is defined as a foreign key when it is defined as a foreign key constraint.constraint.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 3232

Domain as a user/schemaDomain as a user/schema

Domain as a user/schemaDomain as a user/schema A user domain contains a set of user-A user domain contains a set of user-

defined constraints, types, structures and defined constraints, types, structures and tables.tables.

A user domain can grant privileges to A user domain can grant privileges to other user/schema domains.other user/schema domains.

A user domain can hold privileges to other A user domain can hold privileges to other user/schema components.user/schema components.

A user domain can assign aliases in the A user domain can assign aliases in the catalog to point to its own components or catalog to point to its own components or another user/schema components.another user/schema components.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 3333

Domain as a modelDomain as a model

The domain is modeled by visual The domain is modeled by visual drawings or representational drawings or representational semantics.semantics.

The domain is modeled to support The domain is modeled to support understanding what is stored where understanding what is stored where and how it all ties together.and how it all ties together.

The domain is defined visually and The domain is defined visually and by annotation of drawings.by annotation of drawings.

Copyright @2006, Michael McLaughlinCopyright @2006, Michael McLaughlin 3434

SummarySummary

Domains & domain analysisDomains & domain analysis Using domainsUsing domains Importance of domainsImportance of domains Domain of modelsDomain of models