HYSQL  

¡¡

Chapter 4 - Data definition of HYSQL

Data definition defines the structure of the database,including basic table,index and view.

4.1 Basic table

1. CREATE TABLE statement
Syntax: CREATE TABLE TableName (FieldName1 FieldType [(nFieldWidth)] [NULL | NOT NULL],...)

Here,HYSQL supports the following fieldtypes:

BOOL:1 byte;
DATE:4 byte;
TIME:4 byte;

CHAR:the maximum width is 65,000 byte;

Exact number type{BYTE:1 byte,INTEGER:4 byte,LONG:8 byte};
Approximate number type{FLOAT:4 byte,the available digit is 7;DOUBLE:8 byte,the available digit is 15.}

OBJECT:the maximum width is 65,000 byte.

The option 'NULL | NOT NULL' define whether a column is null or not.

BOOL,DATE,TIME,BYTE,INTEGER,LONG specifies BOOL,DATE,TIME,BYTE,INTEGER,LONG;however, CHAR ,FLOAT,DOUBLE,OBJECT respectively specifies CHAR(nFieldWidth),FLOAT(nPrecision),DOUBLE(nPrecision),OBJECT(nFieldWidth)  respectively. 

2. ALTER TABLE statement
Syntax: ALTER TABLE tablename ADD fieldname FieldType [(nFieldWidth])] [NULL | NOT NULL]

3. DROP TABLE statement
Syntax: DROP TABLE tablename

4.2 Index

1.CREATE INDEX statement
Syntax: CREATE [UNIQUE] INDEX indexname  ON basictable (column[ASC | DESC] [,column[ASC | DESC]...)
Here, ASC, DESC respectively specifies sort ascending,sort descending,the default is ASC.
(1)  The index can contain multiple index fields,named compound  index.The important field must be the first in the compound index.
(2)  UNIQUE specifes the index key is unique,that is all records added with duplicate index keys are excluded from the index file. 
(3) You can create multiple index files on a table.

2. DROP VIEW statement
Syntax: DROP VIEW viewname

4.3 View

The view is a table exported from one or more basic tables.Exporting is done by defining a SELECT query.Therefore the importance of the CREATE VIEW statement is the SELECT query.

1. CREATE VIEW statement
Syntax: CREATE VIEW viewname AS SELECT subquery

2. DROP VIEW statement
Syntax: DROP VIEW viewname

View is a important conception in the relational database,its advantages are as follows:
(1)Providing  logic independence to some extent.
(2)Simplifying the user-oriented data structure.
(3)Conveniencing the user to use the database,to view the same data is different from the diffirent users point of view.
(4)Providing a data security on row and column level.
(5)Implementing integrality control to some extent.

  Return


¡¡