|
培训: 001 Lesson 8-9
[php]
Lession8 Overview of data Modeling and Database Design
* System Development Cycle
1. Strategy and Analysis
2. Design
3. Build and Document
4. Transition
5. Production
* Entity relationship models are derived from business specifications or narratives.
* Component Description
-------------------------------------------------------------------------------------
Entity A thing of significance about which information needs to be known.
Attribute Something that describes or qualifies an entity.
Relationship A named association between entities showing optionality or degree.
* One-to-one Degree of one and only one in both directions. These types are rare, and may really be the same entity, or an attribute
of the entity.
Many-to-one Degree of one or more in one direction and a degree of one and only one in the other direction. Very common.
Many-to-many Degree of one or more in both directions. Very common. Resolve them with an intersection entity.
* First normal form (1NF) All attributes must be single-valued and not repeating.
Second normal form (2NF) An attribute must depend upon its entity’s entire unique identifier.
Third normal form (3NF) No non-UID attribute can be dependent upon another non-UID attribute.
* Integrity Constraint Type Description
--------------------------------------------------------------------------------
Entity No part of a primary key can be NULL and the value must be unique.
Referential Foreign key values must match a primary key or be NULL.
Column Values in the column must match the defined datatype.
User-defined Values must comply with the business rules.
* A primary key consisting of multiple columns is called a composite primary key or a compound primary key.
* A foreign key (FK) is a column or combination of columns in one table that refers to a primary key or unique key in the same table or in another table.
* Database Design Steps
1. Map the Entities to Tables
2. Map the Attributes to Columns: Map mandatory attributes, tagged with an asterisk (*), to columns defined as NOT NULL (NN).
3. Map the Unique Identifiers to Primary Keys: symbol (#) to primary key columns and label the key type as PK.
4. Map relationship to foreign keys.
-----------------------------------------------
Lession9 Creating Tables
* When create table, you can use $, _, # , number for table name and column name, must start with character (重点)
* Tables can have up to 254 columns and must conform to standard database object naming conventions. -- 8i中没有限制
* A schema is a collection of objects. Schema objects are the logical structures that directly refer to the data in a database. Schema objects include tables, views, synonyms, sequences, stored procedures, indexes, clusters, and database links.
* The default value can be a literal, an expression, or SQL function, such as SYSDATE and USER, but the value cannot be the name of another column or a pseudocolumn, such as NEXTVAL or CURRVAL. The default expression must match the datatype of the column.
* The basic datatypes are character, number, date, and RAW. --8i中增加了????
* If not refered, default values are available (38 for NUMBER and 1 for CHAR).
* If you do not name your constraint, Oracle7 generates a name with the format SYS_Cn, where n is an integer to create a unique constraint name.
* Null values are allowed if the unique key is based on a single column.
* UNIQUE indexes are created automatically when you create PRIMARY KEY and UNIQUE constraints.
* A foreign key that is part of a primary key cannot be a null value because no part of a primary key can be NULL.
* FOREIGN KEY: Without the ON DELETE CASCADE option, the row in the parent table cannot be deleted if it is referenced in the chil department.
* The CHECK constraint defines a condition that each row must satisfy. The condition can use the same constructs as query conditions, with the following exceptions:
References to the CURRVAL, NEXTVAL, LEVEL, or ROWNUM pseudocolumns
Calls to SYSDATE, UID, USER, or USERENV functions
Queries that refer to other values in other rows
* CHECK constraints can be defined at the column-constraint level or table-constraint level. The constraint syntax can apply to any column in the table, not only on the column on which it is defined. --表级定义CHECK时,可以对多列组合定义,如:CHECK (A+B=10)
* CTAS = CREATE TABLE AS SELECT
The column definition can contain only the column name, default value, and integrity constraints, not the datatype or referential integrity constraint.
Only the NOT NULL constraint is inherited from the subquery table to corresponding columns in the new table.
* 注意定义CONSTRAINTS的语法,在字段级定义时放在“,”前面,在表级定义时,放在最后一个字段定义结束的“,”后面和表定义“)”前面,每个CONSTRAINTS以“,”分开.
* The ENABLE clause can be used in the ALTER TABLE and CREATE TABLE commands.
* The keywords PRIVATE and OR REPLACE are invalid when creating a synonym. Triggers may be enabled using the ENABLE clause in the ALTER TABLE command.
* By creating a public synonym for the table owned by user, you have eliminated the need to qualify an object name with its schema name. The CREATE PUBLIC SYNONYM statement makes a synonym accessible to all users. -- 对用户自身拥有的表建立同义词时,需要去除SCHEMA前缀
* In CTAS: The datatypes of the new table need not be defined as Oracle knows what the datatypes of the original table are. The column names do not have to be specified unless they are to be given a different name than is used in the original table. -- 在CTAS中,不要指定列类型,除非需要更改列名才需要指定列名. The only constraint that is inherited is the NOT NULL constraint. -- 在CTAS中,只有NOT NULL约束被继承
* The size of a table does NOT need to be specified.
[/php] |
|