1. Trang chủ
  2. » Công Nghệ Thông Tin

MySQL Administrator''''s Bible- P15

50 302 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề MySQL Data Dictionary
Trường học MySQL
Chuyên ngành Database Management
Thể loại document
Năm xuất bản Not specified
Thành phố Not specified
Định dạng
Số trang 50
Dung lượng 0,92 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

The value isNULLfor views, because there is no data stored.. ■ CHECK_TIME— The most recentDATETIMEthe table was checked withCHECK TABLE.The value isNULLfor views, system views, and table

Trang 1

MySQL stores information about the data in the databases; this

is called metadata Much of this information is stored in the

INFORMATION_SCHEMAdatabase, following the SQL 2003standard

Tables in theINFORMATION_SCHEMAdatabase are read-only, in-memory,and show data from various sources

SHOW CREATE TABLEwill show the tables asTEMPORARY, becausethey reside in memory and do not persist betweenmysqldrestarts

INFORMATION_SCHEMAtables are called system views and they may be of

different storage engine types At the time of this writing all the systemviews are either the MEMORY, MyISAM, or Maria storage engine

Regular SQL statements can be used to query them, though they havesome special properties that other views do not have:

■ mysqldumpwill not export any information (data, schema) from

INFORMATION_SCHEMAsystem views

■ There is no data directory for theINFORMATION_SCHEMAdatabase

■ There is no.frmfile associated with theINFORMATION_SCHEMA

views The definitions are hard-coded into the database

The table definitions for the data dictionary are hard-coded into the sourcecode, and loaded whenmysqldstarts Unlike other databases, there is

no directory in thedatadirfor theINFORMATION_SCHEMAdatabase

All users have permission to see theINFORMATION_SCHEMAdatabase;

however, they can only see the objects they have permission to see Forexample, table details in theTABLESsystem view are limited to the tablesthat the user has permission to see

Trang 2

Some of the metadata provided by theINFORMATION_SCHEMAdatabase is also provided byvariousSHOWcommands (see Chapter 4) TheINFORMATION_SCHEMAdatabase is a morecomplete data dictionary than usingSHOWcommands Also, standard SQL statements can beused to query the system views to retrieve metadata.

TheINFORMATION_SCHEMAdatabase contains more than 40 system views They can be mally categorized as:

infor-■ Object catalog (databases, tables, columns, and so on)

■ System information (variables, statistics, available options)

■ Permissions

■ Storage engine-specific metadataQuerying metadata is a powerful tool for a database administrator, answering simple questionssuch as ‘‘how many tables of each storage engine type exist?’’ and ‘‘which tables have columnsusing theDECIMALtype?’’ and ‘‘how many foreign key constraints exist?’’ and even ‘‘how muchspace does a certain group of three tables use?’’ Querying metadata provides a way to retrieveinformation about the system that can be used to track and tune performance Any tool that per-forms queries can retrieve metadata by querying theINFORMATION_SCHEMAdatabase, exactlythe same way it queries any other database

Object Catalog

TheINFORMATION_SCHEMAdatabase contains system views with metadata about objects such asdatabases, tables, views, columns, indexes, partitions, stored routines, triggers, and events

SCHEMATA

‘‘Schema’’ is another name for a database, and ‘‘schemata’’ is the plural of schema The

SCHEMATAsystem view in theINFORMATION_SCHEMAdatabase provides information about allthe databases, including themysqlsystem database and theINFORMATION_SCHEMAdatabaseitself The fields in theSCHEMATAsystem view are:

■ CATALOG_NAME— Provided for standards compliance However, because MySQL doesnot have catalogs, this value is alwaysNULL

■ SCHEMA_NAME— The name of the database, such assakila

■ DEFAULT_CHARACTER_SET_NAME— The default character set of the database If nodefault character set is assigned by aCREATE DATABASEorALTER DATABASEcommand,the default character set for the system is stored Thus, theDEFAULT_CHARACTER_SET_ NAMEfield always has a non-NULLvalue, and defaults to the character set of the system atthe time of database creation

Trang 3

■ DEFAULT_COLLATION_NAME— The default collation of the database If no defaultcollation is assigned by aCREATE DATABASEorALTER DATABASEcommand, the defaultcollation for the system is stored Thus, theDEFAULT_CHARACTER_SET_NAMEfieldalways has a non-NULLvalue, and defaults to the collation of the system at the time ofdatabase creation.

■ SQL_PATH— Provided for standards compliance, this field is usually used to find filesrelated to the database However, MySQL does not support this field, so it is alwaysNULL.TheSHOW DATABASEScommand is a shorter way to find the names of existing databases thanrunningSELECT SCHEMA_NAME FROM SCHEMATA To show a subset of all databases, it is easier

to use theSCHEMATAsystem view TheSHOW DATABASEScommand returns a result set wherethe field name isDatabase BecauseDatabaseis a reserved word, in order to use theWHERE

extension toSHOW DATABASES, theDatabasefield must be quoted:

mysql> SHOW DATABASES WHERE Database NOT IN (’mysql’,’information_

schema’);

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ’NOT IN (’mysql’,’information_schema’)’ at line 1 mysql> SHOW DATABASES WHERE `Database` NOT IN (’mysql’,’information_

schema’);

+ -+

| Database | + -+

| sakila |

| test | + -+

2 rows in set (0.02 sec)

See Chapter 4 for more information about using the backtick (`) to quote identifiers

The field name in theSCHEMATAsystem view isSCHEMA_NAME, which is not a reserved word,and does not need to be escaped:

mysql> USE INFORMATION_SCHEMA;

Database changed mysql> SELECT SCHEMA_NAME FROM SCHEMATA WHERE SCHEMA_NAME NOT IN (’mysql’,’information_schema’);

+ -+

| SCHEMA_NAME | + -+

| sakila |

| test | + -+

2 rows in set (0.02 sec)

TheSHOW DATABASEScommand also accepts theLIKEextension TheSHOW SCHEMAS

command behaves the same way as theSHOW DATABASEScommand, and outputs the sameinformation —SCHEMASis an alias forDATABASES

Trang 4

TheSHOW CREATE DATABASEcommand returns two fields:Database, which is equivalent to

SCHEMA_NAME, andCreate Database, which does not have an exact equivalent but containsthe value of DEFAULT_CHARACTER_SET_NAME.SCHEMAis an alias forDATABASE, soSHOW CREATE SCHEMAreturns the same information asSHOW CREATE DATABASEdoes

TABLES

Metadata about non-temporary tables is available in theTABLESsystem view The fields in the

TABLESsystem view are:

■ TABLE_CATALOG— Provided for standards compliance However, because MySQL doesnot have catalogs, this value is alwaysNULL

■ TABLE_SCHEMA— The name of the database, such assakila

■ TABLE_NAME— The name of the table

■ TABLE_TYPE— Whether the table is a base table, view, or system view Only the MATION_SCHEMAviews are system views

INFOR-■ ENGINE— The storage engine of the table, such as InnoDB To find out which tables, ifany, in theINFORMATION_SCHEMAdatabase do not use the MEMORY storage engine:

mysql> SELECT TABLE_NAME,ENGINE FROM TABLES WHERE TABLE_

SCHEMA=’INFORMATION_SCHEMA’ AND ENGINE!=’MEMORY’;

+ -+ -+

| TABLE_NAME | ENGINE | + -+ -+

9 rows in set (0.56 sec)

■ From this query we see that most system views in theINFORMATION_SCHEMAdatabaseare the MEMORY storage engine, but there are some that use the Maria storage engine

■ VERSION— The version of the.frmfile, currently 10 TheVERSIONisNULLfor tableobjects that do not have.frmfiles, such as views The exception to this rule is systemviews, which have aVERSIONof 10 — even though there are no.frmfiles, system viewshave hard-coded definitions, and thus have versions

■ ROW_FORMAT— Different storage engines allow the row storage to vary Fixed-widthrows are a fixed size, which minimizes fragmentation Dynamic rows are a variable size,which are good for variable-length data, such asVARCHAR,TEXT, andBLOB InnoDB has

Trang 5

a compact row format by default, which eliminates some redundant data When an oDB table has a redundant format, there is less CPU work needed at the cost of additionalstorage space MyISAM has a compressed format, obtained by packing the data with the

Inn-myisampacktool See Chapter 11 for more details onmyisampack

■ TABLE_ROWS— The number of rows this table contains This value may be an estimate,depending on the storage engine The value isNULLfor views and system views(INFORMATION_SCHEMAtables)

■ AVG_ROW_LENGTH— The average size in bytes of rows this table contains This value may

be an estimate, depending on the storage engine The value isNULLfor views, but has avalue for system views If there are no rows, the value will be 0

■ DATA_LENGTH— The size in bytes of rows this table contains This value may be an mate, depending on the storage engine The value isNULLfor views and 0 for MEMORYtables System views that are not MEMORY tables have a value forDATA_LENGTH

esti-■ MAX_DATA_LENGTH— The maximum size in bytes that this table may contain The value

isNULLfor views, because there is no data stored The value is 0 for storage engines that

do not populate this field, such as Falcon and CSV

■ INDEX_LENGTH— The size in bytes of the indexes for this table This value may be anestimate, depending on the storage engine The value isNULLfor views and 0 for MEM-ORY tables System views that are not MEMORY tables have a value forDATA_LENGTH

■ DATA_FREE— The size in bytes of the free space allocated for this table, and still able This value may be an estimate, depending on the storage engine The value isNULL

avail-for views and 0 avail-for system views Many tables have aDATA_FREEvalue of 0 because there

is not space allocated for them, though there may be plenty of free space available tothem For example, CSV tables simply use available disk space, without needing MySQL

to allocate space for rows In some storage engines such as MyISAM, this might indicatefragmentation and that the table needs to be rebuilt with anOPTIMIZEcommand SeeChapter 4 for more information aboutOPTIMIZE

■ AUTO_INCREMENT— The nextAUTO_INCREMENTvalue to be used If the maximum

AUTO_INCREMENTvalue for a table is 100, the value ofAUTO_INCREMENTis 101 If atable has anAUTO_INCREMENTvalue and no rows have ever been stored in the table, thevalue ofAUTO_INCREMENTis 1

■ CREATE_TIME— TheDATETIMEthe table was created The value isNULLfor views andMEMORY tables System views that use storage engines other than MEMORY have aproperDATETIMEvalue FEDERATED tables have a value ofNULL

■ UPDATE_TIME— The most recentDATETIMEthat anALTER TABLEwas performed onthe table The value isNULLfor views, CSV, and MEMORY tables MyISAM, Archive, andMaria tables that have never hadALTER TABLEperformed on them have anUPDATE_TIME

equivalent to theirCREATE_TIME InnoDB and Falcon tables that have never hadALTER TABLEperformed on them have aNULLvalue System views that use storage enginesother than MEMORY have a properDATETIMEvalue FEDERATED tables have a value

ofNULL

Trang 6

■ CHECK_TIME— The most recentDATETIMEthe table was checked withCHECK TABLE.The value isNULLfor views, system views, and tables that have never been checked or donot support the check function.

■ TABLE_COLLATION— The character set and collation of the table, for example

utf8_bin utf8_general_ci, orlatin1_swedish_ci The value isNULLfor views

If no default character set and collation is assigned by aCREATE TABLEorALTER TABLE

command, the default character set and collation are stored Thus, this field always has anon-NULLvalue for base tables and system views

■ CHECKSUM— Live checksums can be maintained for MyISAM tables (see Chapter 11) Ifthis table is a MyISAM table withCHECKSUM=1, the live checksum value is displayed Forall other tables, the value isNULL

■ CREATE_OPTIONS—CREATE TABLEhas many different options The options that are notshown in other fields (such asTABLE_COLLATION) are shown in this field, separated by aspace Sample values arepartitionedandmax_rows=10000 checksum=1 If there are

no relevant options toCREATE TABLE, the value is the empty string (’’) The value isNULL

for views

■ TABLE_COMMENT— TheCOMMENToption toCREATE TABLEandALTER TABLEcan beused to provide information about a table If there was no comment specified, the value isthe empty string (‘’) The value isVIEWfor views Most of the tables in themysqlsystemdatabase have comments:

mysql> SELECT TABLE_NAME, TABLE_COMMENT FROM TABLES WHERE TABLE_SCHEMA=’mysql’\G

*************************** 1 row ***************************

TABLE_NAME: backup_history TABLE_COMMENT:

*************************** 2 row ***************************

TABLE_NAME: backup_progress TABLE_COMMENT:

*************************** 3 row ***************************

TABLE_NAME: columns_priv TABLE_COMMENT: Column privileges

*************************** 4 row ***************************

TABLE_NAME: db TABLE_COMMENT: Database privileges

*************************** 5 row ***************************

TABLE_NAME: event TABLE_COMMENT: Events

*************************** 6 row ***************************

TABLE_NAME: func TABLE_COMMENT: User defined functions

*************************** 7 row ***************************

TABLE_NAME: general_log TABLE_COMMENT: General log

*************************** 8 row ***************************

TABLE_NAME: help_category

Trang 7

TABLE_COMMENT: help categories

*************************** 9 row ***************************

TABLE_NAME: help_keyword TABLE_COMMENT: help keywords

*************************** 10 row ***************************

TABLE_NAME: help_relation TABLE_COMMENT: keyword-topic relation

*************************** 11 row ***************************

TABLE_NAME: help_topic TABLE_COMMENT: help topics

*************************** 12 row ***************************

TABLE_NAME: host TABLE_COMMENT: Host privileges; Merged with database privileges

*************************** 13 row ***************************

TABLE_NAME: ndb_binlog_index TABLE_COMMENT:

*************************** 14 row ***************************

TABLE_NAME: plugin TABLE_COMMENT: MySQL plugins

*************************** 15 row ***************************

TABLE_NAME: proc TABLE_COMMENT: Stored Procedures

*************************** 16 row ***************************

TABLE_NAME: procs_priv TABLE_COMMENT: Procedure privileges

*************************** 17 row ***************************

TABLE_NAME: servers TABLE_COMMENT: MySQL Foreign Servers table

*************************** 18 row ***************************

TABLE_NAME: slow_log TABLE_COMMENT: Slow log

*************************** 19 row ***************************

TABLE_NAME: tables_priv TABLE_COMMENT: Table privileges

*************************** 20 row ***************************

TABLE_NAME: time_zone TABLE_COMMENT: Time zones

*************************** 21 row ***************************

TABLE_NAME: time_zone_leap_second TABLE_COMMENT: Leap seconds information for time zones

*************************** 22 row ***************************

TABLE_NAME: time_zone_name TABLE_COMMENT: Time zone names

*************************** 23 row ***************************

TABLE_NAME: time_zone_transition TABLE_COMMENT: Time zone transitions

*************************** 24 row ***************************

TABLE_NAME: time_zone_transition_type TABLE_COMMENT: Time zone transition types

Trang 8

*************************** 25 row *************************** TABLE_NAME: user

TABLE_COMMENT: Users and global privileges

25 rows in set (0.00 sec)

There are a fewSHOWcommands that show table information.SHOW TABLESreturns one field,the equivalent of TABLE_NAME.SHOW FULL TABLESadds another field,Table_type, which

is the equivalent ofTABLE_TYPE.TheSHOW CREATE TABLEcommand returns two fields:Table, which is the equivalent of

TABLE_NAME, andCreate Table, which is the fullCREATE TABLEstatement There is

no equivalent in theTABLESsystem view, though it includes the information inENGINE,

AUTO_INCREMENT,CREATE_OPTIONS, andTABLE_COMMENT

SHOW TABLE STATUSreturns many fields:

■ Name— Equivalent toTABLE_NAME

■ Engine,Version, andRow_format— Equivalent toENGINE,VERSION, and

ROW_FORMAT

■ Rows— Equivalent toTABLE_ROWS

■ Avg_row_length,Data_length,Max_data_length,Index_length,Data_free,

Auto_increment,Create_time,Update_time, andCheck_time— Equivalent to

AVG_ROW_LENGTH,DATA_LENGTH,MAX_DATA_LENGTH,INDEX_LENGTH,DATA_FREE,

AUTO_INCREMENT,CREATE_TIME,UPDATE_TIME, andCHECK_TIME

■ Collation— Equivalent toTABLE_COLLATION

■ Checksum,Create_options— Equivalent toCHECKSUMandCREATE_OPTIONS

■ Comment— Equivalent toTABLE_COMMENT

VIEWS

TheTABLESsystem view includes rows for views However, many of the fields inTABLESare

NULLfor views, and some features specific to views are not encompassed in theTABLESsystemview So MySQL provides theVIEWSsystem view, with the following fields:

■ TABLE_CATALOG— Provided for standards compliance However, because MySQL doesnot have catalogs, this value is alwaysNULL

■ TABLE_SCHEMA— The name of the database, such assakila

■ TABLE_NAME— The name of the view

■ VIEW_DEFINITION— TheSELECTstatement that defines the view If the current user isnot the definer, the value will be blank, even if the current user has permissions to see theview definition:

mysql> SELECT DEFINER,VIEW_DEFINITION,CURRENT_USER() -> FROM VIEWS

-> WHERE TABLE_NAME=’staff_list’;

Trang 9

| DEFINER | VIEW_DEFINITION | CURRENT_USER() | + -+ -+ -+

| root@localhost | | root@127.0.0.1 | + -+ -+ -+

1 row in set (0.03 sec)

mysql> SHOW GRANTS;

1 row in set (0.00 sec)

mysql> SHOW CREATE VIEW sakila.staff_list\G

*************************** 1 row ***************************

View: staff_list Create View: CREATE ALGORITHM=UNDEFINED DEFINER=root@

localhost SQL SECURITY DEFINER VIEW sakila.staff_list AS select s.staff_id AS ID,concat(s.first_name,_utf8’ ’,s.last_name) AS name, a.address AS address,a.postal_code AS zip code,a.phone AS phone, sakila.city.city AS city,sakila.country.country AS country,s.

store_id AS SID from (((sakila.staff s join sakila.address a on((s.address_id = a.address_id))) join sakila.city on((a.city_id

= sakila.city.city_id))) join sakila.country on((sakila.city.

country_id = sakila.country.country_id))) character_set_client: utf8mb3

collation_connection: utf8mb3_general_ci

1 row in set (0.00 sec)

■ In this example, the userroot@127.0.0.1saw a blank view definition for the

staff_listview, because theDEFINERisroot@localhost

■ CHECK_OPTION— This value isNONEif the view definition has noWITH CHECK OPTION

clause;CASCADEDif the view definition containsWITH [CASCADED] CHECK OPTION, and

LOCALif the view definition containsWITH LOCAL CHECK OPTION

■ IS_UPDATABLE—YESif the view is updatable,NOif the view is not updatable SeeChapter 8, subsection ‘‘Updatable Views,’’ for more information on updatable views

■ DEFINER— The view definer, in the MySQLuser@hostformat

■ SECURITY_TYPE—DEFINERif the view definition was specified with theSQL SECURITY DEFINERoption or did not contain anSQL SECURITYoption The value is

INVOKERif the view definition was specified with theSQL SECURITY INVOKERoption

■ CHARACTER_SET_CLIENT— Stores the environmental character set as it was when theview was created

Trang 10

■ COLLATION_CONNECTION— Stores the environmental collation as it was when the viewwas created.

SHOW CREATE VIEWis theSHOWcommand that shares the most information with theVIEWStem view The fields of SHOW CREATE VIEWare:

sys-■ View— Equivalent toTABLE_NAME

■ Create View— No exact equivalent This is the fullCREATE VIEWstatement, and haselements fromTABLE_NAME,VIEW_DEFINITION,CHECK_OPTION,IS_UPDATABLE,

DEFINER, andSECURITY_TYPE

■ character_set_client— Equivalent toCHARACTER_SET_CLIENT

■ collation_connection— Equivalent toCOLLATION_CONNECTION

■ TABLE_SCHEMA— The name of the database, such assakila

■ TABLE_NAME— The name of the table

■ COLUMN_NAME— The name of the field

■ ORDINAL_POSITION— The number representing the order of the field The first field has

a value of 1, the third field has a value of 3, and so on The value is neverNULL

■ COLUMN_DEFAULT— The default value of the field If the default is not specified or fied asNULL, the value isNULL

speci-■ IS_NULLABLE— Whether or not the field is allowed to be null If the field is specified as

NOT NULL, the value isNO Otherwise, the value isYES Note that it is possible to have atable where the value ofIS_NULLABLEisNOand theCOLUMN_DEFAULTisNULL:

mysql> USE test;

Database changed mysql> CREATE TABLE paradox (numfield INT NOT NULL);

Query OK, 0 rows affected (0.11 sec) mysql> SELECT IS_NULLABLE,COLUMN_DEFAULT -> FROM INFORMATION_SCHEMA.COLUMNS -> WHERE TABLE_NAME=’paradox’ AND TABLE_SCHEMA=’test’;

+ -+ -+

| IS_NULLABLE | COLUMN_DEFAULT | + -+ -+

| NO | NULL | + -+ -+

1 row in set (0.00 sec)

Trang 11

■ DATA_TYPE— The data type of the field, such asINT,CHAR, orENUM.

■ CHARACTER_MAXIMUM_LENGTH— The maximum number of characters allowed bythe field definition For example, a field defined asVARCHAR(64)has aCHARAC- TER_MAXIMUM_LENGTHof 64 This is only valid for string data, which includesCHAR,

VARCHAR,TEXT,BLOB,SET, andENUMtypes

■ CHARACTER_OCTET_LENGTH— Maximum octet (byte) size allowed by the field tion.CHARACTER_OCTET_LENGTHis the same asCHARACTER_MAXIMUM_LENGTHexceptwhen multi-byte character sets are used (such asutf8)

defini-■ NUMERIC_PRECISION— Mathematically, precision is the number of digits used to define

a number, for example 10 for anINTand 5 for aSMALLINT This is only valid for numericdata types, includingINT,DECIMAL, andFLOAT For all other data types, the value is

NULL

■ NUMERIC_SCALE— This is only valid for numeric data types, includingINT,DECIMAL,andFLOAT For all other data types, the value isNULL This value is equivalent to thenumber of digits after the decimal point, which is 0 for data types that are integers

■ CHARACTER_SET_NAME— The default character set for this column This is only valid fornon-binary string data, which includesCHAR,VARCHAR,TEXT,SET, andENUMtypes

■ COLLATION_NAME— The default collation for this column This is only valid fornon-binary string data, which includesCHAR,VARCHAR,TEXT,SET, andENUMtypes

Sample values areutf8_general_ci,latin1_bin, andlatin1_swedish_ci

■ COLUMN_TYPE— The entire data type part of the column definition, without any

NULLorDEFAULTdefiners For example,varchar(64),bigint(21) unsigned,

enum(’N’,’Y’), oryear(4)

■ COLUMN_KEY— If the column is not part of an index, this field contains the empty string(‘’) Otherwise, the value is the type of index the columns is a part of:

■ PRI— Primary key

■ UNI— Unique, non-primary key

■ MUL— Non-unique key

■ EXTRA— This field stores extra information about the column that does not have a place

in another field If there is no such extra information, the value is the empty string (‘’)

Example values areon update CURRENT_TIMESTAMPandauto_increment

■ PRIVILEGES— The privileges the querying user has for use with this column If the userhas no privileges for a column, there is no row returned for that column Therefore, thefield always contains at least theselectprivilege Privileges are separated by a comma,for exampleselect,insert,update

■ COLUMN_COMMENT— TheCOMMENToption to a column definition withinCREATE TABLE

andALTER TABLEcan be used to provide information about a column If there was nocomment specified, the value is the empty string (‘’)

Trang 12

■ STORAGE— Indicates whether the column is stored in memory or on disk These onlyapply to columns in NDB tables The value for all other tables isDefault.

■ FORMAT— Indicates whether the column storage format is fixed, dynamic, or default.Fixed and dynamic storage formats only apply to columns in NDB tables The value for allother tables isDefault

TheSHOW COLUMNScommand is theSHOWcommand that shares the most information with the

COLUMNSsystem view It accepts theLIKEandWHEREextensions, and will show three extrafields when theSHOW FULL COLUMNSsyntax is used:

mysql> SHOW COLUMNS FROM sakila.staff LIKE ’s%’\G

*************************** 1 row ***************************

Field: staff_id Type: tinyint(3) unsigned Null: NO

Key: PRI Default: NULL Extra: auto_increment

*************************** 2 row ***************************

Field: store_id Type: tinyint(3) unsigned Null: NO

Key: MUL Default: NULL Extra:

2 rows in set (0.00 sec)

mysql> SHOW FULL COLUMNS FROM sakila.staff LIKE ’s%’\G

*************************** 1 row ***************************

Field: staff_id Type: tinyint(3) unsigned Collation: NULL

Null: NO Key: PRI Default: NULL Extra: auto_increment Privileges: select,insert,update,references Comment:

*************************** 2 row ***************************

Field: store_id Type: tinyint(3) unsigned Collation: NULL

Null: NO Key: MUL Default: NULL Extra:

Trang 13

Privileges: select,insert,update,references Comment:

2 rows in set (0.00 sec)

The fields fromSHOW COLUMNSandSHOW FULL COLUMNSare:

■ Field— Equivalent toCOLUMN_NAME

■ Type— Equivalent toCOLUMN_TYPE

■ Collation— Equivalent toCOLLATION_NAME.SHOW FULL COLUMNSonly

■ Null— Equivalent toIS_NULLABLE

■ Key— Equivalent toCOLUMN_KEY

■ Default— Equivalent toCOLUMN_DEFAULT

■ Extra— Equivalent toEXTRA

■ Privileges— Equivalent toPRIVILEGES.SHOW FULL COLUMNSonly

■ Comment— Equivalent toCOLUMN_COMMENT.SHOW FULL COLUMNSonly

SHOW COLUMNSreturns the fields in the order in which they appear in the table To guaranteethat ordering with theCOLUMNSsystem view, addORDER BY ORDINAL_POSITIONto queries

■ TABLE_NAME— The name of the table that is associated with this index

■ NON_UNIQUE— Whether or not the index is unique The value is 0 for unique indexesand 1 for non-unique indexes

■ INDEX_SCHEMA— The name of the database that contains this index This is always thesame asTABLE_SCHEMA

■ INDEX_NAME— The name of the index

■ SEQ_IN_INDEX— The position of this field in the index The first field in an index has

a value of 1, the second field in an index has a value of 2, and so on For example, the

sakila.rentaltable has an index defined as:

UNIQUE KEY `rental_date` (`rental_date`,`inventory_id`,

`customer_id`),

Trang 14

This index is represented by three rows in theSTATISTICSsystem view:

mysql> SELECT SEQ_IN_INDEX, COLUMN_NAME -> FROM STATISTICS

| 1 | rental_date |

| 2 | inventory_id |

| 3 | customer_id | + -+ -+

3 rows in set (0.00 sec)

■ COLUMN_NAME— The name of the field

■ COLLATION— The collation for this field Currently all records haveNULLvalues ever, in the future, whenmysqldsupports ascending and descending collations, the valuewill beAfor ascending collations andDfor descending collations

How-■ CARDINALITY— The cardinality of this field The cardinality of a field is the number ofunique values in that field This value may be an estimation, depending on the storageengine of the table If the cardinality is small compared to the number of rows in the table,

it means that there are many repeating values This means a query will return multiplevalues for a field when searching on a value that is indexed, but repeating

When the field cardinality is large, approaching the value of the number of rows, it meansthat there are very few repeating values Fields in a unique index have a cardinality equal

to the number of rows in the table

■ SUB_PART— The number of characters in the prefix of the index for this field Ifthe index does not contain a prefix for this field, the value isNULL For example, the

sakila.filmtable has the following index defined:

KEY `idx_title` (`title`(191)),

And the value ofSUB_PARTis 191:

mysql> SELECT INDEX_NAME, COLUMN_NAME, SUB_PART -> FROM STATISTICS

1 row in set (0.00 sec)

Trang 15

■ PACKED— Whether or not the index is packed This only applies to MyISAM tables Ifthe index is not packed, the value isNULL If the index is packed, the value is0(nothingpacked),1(strings and integers are packed), orDEFAULT(only strings are packed).

■ NULLABLE— Whether or not the field can containNULLvalues If the field can contain

NULLvalues, the value isYES If the field cannot containNULLvalues, the value is theempty string (‘’)

■ INDEX_TYPE— The type of index Example values areBTREE,FULLTEXT,HASH, and

RTREE

■ COMMENT— Always the empty string (‘’)

■ INDEX_COMMENT— The comment defined by theindex_commentoption when creating

or changing an index

The output of SHOW INDEXis very similar to the fields in theSTATISTICSsystem view:

■ Table— Equivalent toTABLE_NAME

■ Non_unique— Equivalent toNON_UNIQUE

■ Key_name— Equivalent toINDEX_NAME

■ Seq_in_index,Column_name,Collation,Cardinality,Sub_part,Packed,

Null,Index_type,Comment, andIndex_Comment— Equivalent toSEQ_IN_INDEX,

COLUMN_NAME,COLLATION,CARDINALITY,SUB_PART,PACKED,NULLABLE,

INDEX_TYPE,COMMENT, andINDEX_COMMENT

TABLE_CONSTRAINTS

Unique and primary keys restrict data values in a table, only allowing one set of values for thefields in those indexes A foreign key restricts the allowable data for fields in a table by onlyallowing values from another set of fields The restrictions that unique, primary, and foreignkeys place on tables are referred to as table constraints TheTABLE_CONSTRAINTSsystem viewhas information about unique keys, primary keys, and foreign keys in the following fields:

■ CONSTRAINT_CATALOG— Provided for standards compliance However, because MySQLdoes not have catalogs, this value is alwaysNULL

■ CONSTRAINT_SCHEMA— The name of the database that the constraint belongs to, such

assakila This is the same as theTABLE_SCHEMAfield

■ CONSTRAINT_NAME— The name of the index The value isPRIMARYfor a primary key.Unique keys and foreign keys have names that can be set when an index is created orchanged The default name for foreign keys starts withfk_

■ TABLE_SCHEMA— The name of the database that the constrained table belongs to

■ TABLE_NAME— The name of the table constrained

■ CONSTRAINT_TYPE— The type of constraint EitherPRIMARY KEY,UNIQUE, or

FOREIGN KEY

Trang 16

There is no equivalentSHOWstatement for the data inTABLE_CONSTRAINTS, but the output of

SHOW INDEXhas some of the same fields:

■ Table— Equivalent toTABLE_NAME

■ Key_name— Equivalent toCONSTRAINT_NAMEfor unique and primary keys For foreignkeys, theKey_nameis the name of the index on the field, and theCONSTRAINT_NAMEisthe name of the foreign key constraint

As an example, in thesakila.stafftable, theaddress_idfield is a foreign key, definedwith:

KEY idx_fk_address_id (address_id), CONSTRAINT fk_staff_address FOREIGN KEY (address_id) REFERENCES address (address_id) ON UPDATE CASCADE,

TheKey_namefromSHOW INDEXisidx_fk_address_id, and theCONSTRAINT_NAMEthatappears in theTABLE_CONSTRAINTSsystem view isfk_staff_address

■ Column_name— Equivalent toCOLUMN_NAME.Note thatSHOW INDEXshows all indexes andTABLE_CONSTRAINTShas information only forunique, primary, and foreign keys

■ CONSTRAINT_SCHEMA— The name of the database that the constraint belongs to, such

assakila This is the same as theTABLE_SCHEMAfield

■ CONSTRAINT_NAME— The name of the index The value isPRIMARYfor a primary key.Unique keys and foreign keys have names that can be set when an index is created orchanged The default name for foreign keys starts withfk_

■ TABLE_CATALOG— Provided for standards compliance However, because MySQL doesnot have catalogs, this value is alwaysNULL

■ TABLE_SCHEMA— The name of the database that the constrained table belongs to

■ TABLE_NAME— The name of the table constrained

■ COLUMN_NAME— The name of the field constrained

■ ORDINAL_POSITION— The constrained field’s position in the index The first field in

an index has a value of 1, the second field has a value of 2, and so on For example, the

sakila.rentaltable has a composite unique index (a unique index with more than onefield):

UNIQUE KEY rental_date (rental_date, inventory_id, customer_id)

Trang 17

TheORDINAL_POSITIONofrental_dateis 1, ofinventory_idis 2, and ofcustomer_id

is 3

■ POSITION_IN_UNIQUE_CONSTRAINT—NULLfor keys that are not foreign keys Forforeign keys, the value is the referenced field’s position in the foreign key

As an example, the foreign keyfk_staff_addresson thesakila.stafftable is defined as:

CONSTRAINT fk_staff_address FOREIGN KEY (address_id) REFERENCES address (address_id) ON UPDATE CASCADE

The value of POSITION_IN_UNIQUE_CONSTRAINTis 1, referring to the fact that the

address_idfield is the first referenced field Foreign keys are usually defined as:

FOREIGN KEY (fld1,fld2) REFERENCES reftbl (reffld1,reffld2)

Thus, thePOSITION_IN_UNIQUE_CONSTRAINTis the same asORDINAL_POSITION

■ REFERENCED_TABLE_SCHEMA—NULLfor keys that are not foreign keys For foreignkeys, the database name of the referenced table As an example, the foreign key

fk_staff_addresson thesakila.stafftable is defined as:

CONSTRAINT fk_staff_address FOREIGN KEY (address_id) REFERENCES address (address_id) ON UPDATE CASCADE

TheREFERENCED_TABLE_SCHEMAissakila, which is the database containing theaddress

SHOW INDEXhas some of the same fields:

■ Table— Equivalent toTABLE_NAME

■ Key_name— Equivalent toCONSTRAINT_NAMEfor unique and primary keys For foreignkeys, theKey_nameis the name of the index on the field, and theCONSTRAINT_NAMEisthe name of the foreign key constraint

As an example, in thesakila.stafftable, theaddress_idfield is a foreign key, definedwith:

KEY idx_fk_address_id (address_id), CONSTRAINT fk_staff_address FOREIGN KEY (address_id) REFERENCES address (address_id) ON UPDATE CASCADE,

TheKey_namefromSHOW INDEXisidx_fk_address_id, and theCONSTRAINT_NAMEthatappears in theTABLE_CONSTRAINTSsystem view isfk_staff_address

■ Column_name— Equivalent toCOLUMN_NAME

Trang 18

Note thatSHOW INDEXshows all indexes andKEY_COLUMN_USAGEhas information only forunique, primary, and foreign keys.

REFERENTIAL_CONSTRAINTS

There is more information about foreign keys than theKEY_COLUMN_USAGEandTABLE_ CONSTRAINTSsystem views show TheREFERENTIAL_CONSTRAINTSsystem view shows thebehavior of a foreign key during updates and deletes These behaviors are defined in the foreignkey constraint with theON UPDATEandON DELETEclauses TheREFERENTIAL_CONSTRAINTS

system view also repeats the constraint and referenced constraint:

■ CONSTRAINT_CATALOG— Provided for standards compliance However, because MySQLdoes not have catalogs, this value is alwaysNULL

■ CONSTRAINT_SCHEMA— The name of the database that the constraint belongs to, such

assakila

■ CONSTRAINT_NAME— The name of the index The value isPRIMARYfor a primary key.Unique keys and foreign keys have names that can be set when an index is created orchanged The default name for foreign keys starts withfk_

■ UNIQUE_CONSTRAINT_CATALOG— Provided for standards compliance However,because MySQL does not have catalogs, this value is alwaysNULL

■ UNIQUE_CONSTRAINT_SCHEMA— The database name of the referenced table This isequivalent to theREFERENCED_TABLE_SCHEMAin theKEY_COLUMN_USAGEsystem view

■ UNIQUE_CONSTRAINT_NAME— The name of the referenced constraint Similar to the

CONSTRAINT_NAMEfield of theKEY_COLUMN_USAGEsystem view, this value isPRIMARY

for a primary key or the name of the index for non-primary keys

■ MATCH_OPTION— This feature has not been implemented yet, so the value is always

NONE

■ UPDATE_RULE— The update behavior of the foreign key, as set by the foreign key tion Possible values areCASCADE,NO ACTION,RESTRICT,SET NULL,SET DEFAULT SeeChapter 6 for more information on defining foreign keys

defini-■ DELETE_RULE— The delete behavior of the foreign key, as set by the foreign key tion Possible values areCASCADE,NO ACTION,RESTRICT,SET NULL,SET DEFAULT SeeChapter 6 for more information on defining foreign keys

defini-■ TABLE_NAME— The table name that the foreign key constraint belongs to

■ REFERENCED_TABLE_NAME— The table name of the referenced table

There is no completeSHOWstatement for the fields inREFERENTIAL_CONSTRAINTS, but the

Key_namefield from the output ofSHOW INDEXis equivalent toCONSTRAINT_NAME

Trang 19

Triggers are user-defined stored SQL that get run when data changes Triggers are defined on

a per-table basis, and can occur before and after inserts, updates, and deletes The fields in the

TRIGGERSsystem view are:

■ TRIGGER_CATALOG— Provided for standards compliance However, because MySQLdoes not have catalogs, this value is alwaysNULL

■ TRIGGER_SCHEMA— The name of the database that the trigger belongs to, such as

sakila

■ TRIGGER_NAME— The name of the trigger

■ EVENT_MANIPULATION— The name of the action that calls this trigger Possible valuesareINSERT,DELETE, orUPDATE

■ EVENT_OBJECT_CATALOG— Provided for standards compliance However, becauseMySQL does not have catalogs, this value is alwaysNULL

■ EVENT_OBJECT_SCHEMA— The name of the database that the table associated with thetrigger belongs to, such assakila

■ EVENT_OBJECT_TABLE— The name of the table associated with the trigger

■ ACTION_ORDER— The order the trigger is run in This value is always 0 because MySQLonly supports one trigger per set ofACTION_TIMINGandEVENT_MANIPULATION

■ ACTION_CONDITION— AlwaysNULL

■ ACTION_STATEMENT— The SQL that is run by the trigger

■ ACTION_ORIENTATION— AlwaysROW

■ ACTION_TIMING— When the trigger occurs Possible values areBEFOREorAFTER

■ ACTION_REFERENCE_OLD_TABLE— AlwaysNULL

■ ACTION_REFERENCE_NEW_TABLE— AlwaysNULL

■ ACTION_REFERENCE_OLD_ROW— How the trigger references the row prior to the datachange This is not settable by the user, and is alwaysOLD

■ ACTION_REFERENCE_NEW_ROW— How the trigger references the row after the data ischanged This is not settable by the user, and is alwaysNEW

■ CREATED— AlwaysNULL

■ SQL_MODE— Stores the environmentalsql_modeas it was when the trigger was created.This is also thesql_modethat is used when the trigger is invoked

■ DEFINER— The trigger definer, in the MySQLuser@hostformat

Trang 20

■ CHARACTER_SET_CLIENT— Stores the environmental character set as it was when thetrigger was created This is also thecharacter_set_clientthat is used when the trig-ger is invoked.

■ COLLATION_CONNECTION— Stores the environmental collation as it was when the ger was created This is also thecollation_connectionthat is used when the trigger isinvoked

trig-■ DATABASE_COLLATION— The default collation of the database associated with thetrigger

For more information on triggers, see Chapter 7

TheSHOW TRIGGERSstatement outputs some of the same information in theTRIGGERSsystemview The equivalent fields are:

■ Trigger— Equivalent toTRIGGER_NAME

■ Event— Equivalent toEVENT_MANIPULATION

■ Table— Equivalent toEVENT_OBJECT_TABLE

■ Statement— Equivalent toACTION_STATEMENT

■ Timing— Equivalent toACTION_TIMING

■ Created,sql_mode,Definer,character_set_client,collation connection— Equivalent toCREATED,SQL_MODE, DEFINER,

CHARACTER_SET_CLIENT,COLLATION_CONNECTION.TheSHOW CREATE TRIGGERstatement outputs the following fields, which are similar to fields intheTRIGGERSsystem view:

■ Trigger— Equivalent toTRIGGER_NAME

■ sql_mode— Equivalent toSQL_MODE

■ SQL Original Statement— This is the entireCREATE TRIGGERstatement, whichincludes the information shown in theEVENT_MANIPULATION,ACTION_ORDER,

ACTION_STATEMENT,ACTION_TIMING, andDEFINERfields

■ character_set_client,collation connection,Database Collation —

Equivalent toCHARACTER_SET_CLIENT,COLLATION_CONNECTION, andDATABASE_ COLLATION

ROUTINES

TheROUTINESsystem view stores metadata about stored procedures and stored routines.For more information on stored routines, see Chapter 7 The fields in theROUTINESsystemview are:

■ SPECIFIC_NAME— The name of the stored routine

■ ROUTINE_CATALOG— Provided for standards compliance However, because MySQLdoes not have catalogs, this value is alwaysNULL

Trang 21

■ ROUTINE_SCHEMA— The name of the database that the stored routine belongs to, such

assakila

■ ROUTINE_NAME— The name of the stored routine This is equivalent to the

SPECIFIC_NAME

■ ROUTINE_TYPE— The type of stored routine, eitherFUNCTIONorPROCEDURE

■ DATA_TYPE— For a stored procedure, this value is the empty string (‘’) For a storedfunction, the data type of the return value, such asINT,CHAR, orENUM

■ CHARACTER_MAXIMUM_LENGTH— For a stored procedure, this value isNULL For astored function, this value is the maximum number of characters allowed by the datatype of the return value For example, a return data type defined asVARCHAR(64)has a

CHARACTER_MAXIMUM_LENGTHof 64 This is only valid for string data, which includes

CHAR,VARCHAR,TEXT,BLOB,SET, andENUMtypes

■ CHARACTER_OCTET_LENGTH— For a stored procedure, this value isNULL For a storedfunction, this value is the maximum octet size allowed by the data type of the return value

CHARACTER_OCTET_LENGTHis the same asCHARACTER_MAXIMUM_LENGTHexcept whenmulti-byte character sets are used (such asutf8)

■ NUMERIC_PRECISION— For a stored procedure, this value isNULL For a stored tion, the number of digits used to define the data type of the return value Example valuesare 10 for anINTand 5 for aSMALLINT This is only valid for numeric data types, includ-ingINT,DECIMAL, andFLOAT For non-numeric data types, the value isNULL

func-■ NUMERIC_SCALE— For a stored procedure, this value isNULL For a stored function,this value isNULLfor non-numeric data types For numeric data types includingINT,

DECIMAL, andFLOAT, this value is equivalent to the number of digits after the decimalpoint, which is 0 for data types that are integers

■ CHARACTER_SET_NAME— For a stored procedure, this value isNULL For a storedfunction, this value is the default character set for the return value This is only valid fornon-binary string data, which includesCHAR,VARCHAR,TEXT,SET, andENUMtypes

■ COLLATION_NAME— For a stored procedure, this value isNULL For a stored function,this value is the default collation for the return value This is only valid for non-binarystring data, which includesCHAR,VARCHAR,TEXT,SET, andENUMtypes Sample valuesareutf8_general_ci,latin1_bin, andlatin1_swedish_ci

■ DTD_IDENTIFIER— For a stored procedure, this value isNULL For a stored function,this value is the definition of the return value For example, a function that defines thereturn value asRETURNS decimal(5,2)has aDTD_IDENTIFIERofdecimal(5,2)

The DATA_TYPE , CHARACTER_MAXIMUM_LENGTH , CHARACTER_OCTET_LENGTH , NUMERIC_

PRECISION , NUMERIC_SCALE , CHARACTER_SET_NAME , COLLATION_NAME , and DTD_IDENTIFIER

fields were added in version 6.0.

■ ROUTINE_BODY— The language that the body of the stored routine is written in rently MySQL only allows SQL, so the value will always beSQL

Trang 22

Cur-■ ROUTINE_DEFINITION— The stored routine SQL statement For multi-statement tines, this field will start withBEGINand the last part of the field will beEND.

rou-■ EXTERNAL_NAME— The name of the stored routine if it is stored externally Because allMySQL stored routines are stored internally, this value is alwaysNULL

■ EXTERNAL_LANGUAGE— The name of the language the stored routine is written in if it

is stored externally Because all MySQL stored routines are stored internally, this value isalwaysNULL

■ PARAMETER_STYLE— The style of parameters that are used in this stored routine rently MySQL only allows SQL, so the value will always beSQL

Cur-■ IS_DETERMINISTIC— Whether or not the stored routine is deterministic See ministic vs Not Deterministic Routines in MySQL’’ in Chapter 7 for more information

‘‘Deter-■ SQL_DATA_ACCESS— The nature of the SQL that the stored routine contains Possiblevalues areMODIFIES SQL DATA,READS SQL DATA,CONTAINS SQL, andNO SQL

■ SQL_PATH— Provided for standards compliance, this field is usually used to find filesrelated to the stored routine However, MySQL does not support this field, so it is always

NULL

■ SECURITY_TYPE—DEFINERif the routine definition was specified with theSQL SECURITY DEFINERoption or did not contain anSQL SECURITYoption The value is

INVOKERif the routine definition was specified with theSQL SECURITY INVOKERoption

■ CREATED— The datetime of the stored routine creation

■ LAST_ALTERED— The datetime the stored routine was last changed If the stored routinehas not changed since it was created, theLAST_ALTEREDtime is equivalent toCREATED

■ SQL_MODE— Stores the environmentalsql_modeas it was when the stored routine wascreated This is also thesql_modethat is used when the stored routine is invoked

■ ROUTINE_COMMENT— TheCOMMENToption toCREATEandALTERstatements for storedroutines can be used to provide user-defined information If there was no comment speci-fied, the value is the empty string (‘’)

■ DEFINER— The stored routine definer, in the MySQLuser@hostformat

■ CHARACTER_SET_CLIENT— Stores the environmental character set as it was when thestored routine was created This is also thecharacter_set_clientthat is used whenthe stored routine is invoked

■ COLLATION_CONNECTION— Stores the environmental collation as it was when thestored routine was created This is also thecollation_connectionthat is used whenthe stored routine is invoked

■ DATABASE_COLLATION— the default collation of the database associated with the storedroutine

TheSHOW PROCEDURE STATUSandSHOW FUNCTION STATUSstatements output some tion that is stored in theROUTINESsystem view:

Trang 23

informa-■ Db— Equivalent toROUTINE_SCHEMA.

■ Name— Equivalent toROUTINE_NAME

■ Type— Equivalent toROUTINE_TYPE

■ Definer— Equivalent toDEFINER

■ Modified— Equivalent toLAST_ALTERED

■ Created— Equivalent toCREATED

■ Security_type— Equivalent toSECURITY_TYPE

■ Comment— Equivalent toROUTINE_COMMENT

■ character_set_client,collation connection,Database Collation—Equivalent toCHARACTER_SET_CLIENT,COLLATION_CONNECTION, andDATABASE_

■ sql_mode— Equivalent toSQL_MODE

■ Create Procedure(SHOW CREATE PROCEDURE) — The entireCREATE PROCEDURE

statement, which includes the information shown in theROUTINE_DEFINITION,

IS_DETERMINISTIC,SQL_DATA_ACCESS,SECURITY_TYPE,ROUTINE_COMMENT, and

DEFINERfields for stored procedures

■ Create Function(SHOW CREATE FUNCTION) — The entireCREATE FUNCTION

statement, which includes the information shown in theDATA_TYPE, TER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,

CHARAC-NUMERIC_SCALE,CHARACTER_SET_NAME,COLLATION_NAME,DTD_IDENTIFIER,

ROUTINE_DEFINITION,IS_DETERMINISTIC,SQL_DATA_ACCESS,SECURITY_TYPE,

ROUTINE_COMMENT, andDEFINERfields for stored functions

■ character_set_client,collation connection,Database Collation—Equivalent toCHARACTER_SET_CLIENT,COLLATION_CONNECTION, andDATABASE_

COLLATION

Stored routines are stored in themysql.proctable, so some of the metadata inROUTINESissimilar to fields in themysql.proctable:

■ db— Equivalent toROUTINE_SCHEMA

■ name— Equivalent toROUTINE_NAME

■ type— Equivalent toROUTINE_TYPE

Trang 24

■ specific_name,language,sql_data_access,is_deterministic, and

security_type— Equivalent toSPECIFIC_NAME,LANGUAGE,SQL_DATA_ACCESS,

IS_DETERMINISTIC, andSECURITY_TYPE

■ returns— Equivalent toDTD_IDENTIFIERfor stored functions For stored procedures,

returnsis the empty string (‘’), whileDTD_IDENTIFIERisNULL

■ body— Equivalent toROUTINE_DEFINITION

■ definer— Equivalent toDEFINER

■ created— Equivalent toCREATED

■ modified— Equivalent toLAST_ALTERED

■ sql_mode— Equivalent toSQL_MODE

■ comment— Equivalent toROUTINE_COMMENT

■ character_set_client— Equivalent toCHARACTER_SET_CLIENT

■ collation_connection— Equivalent toCOLLATION_CONNECTION

■ db_collation— Equivalent toDATABASE_COLLATION

PARAMETERS

TheROUTINESsystem view has a lot of information about stored routines It contains manyfields with information about the return value of a stored function, however there is no informa-tion about input parameters to stored functions, nor is there any information about theIN,OUT,andINOUTparameters in a stored procedure

ThePARAMETERSsystem view, added in MySQL version 6.0, contains information aboutstored routine parameters Each parameter in a stored routine is represented by a row in the

PARAMETERSsystem view, with the following fields:

■ SPECIFIC_CATALOG— Provided for standards compliance However, because MySQLdoes not have catalogs, this value is alwaysNULL

■ SPECIFIC_SCHEMA— The name of the database that the stored routine containing thisparameter For example, if a parameter was stored in a routine associated with thesakila

database, the value ofSPECIFIC_SCHEMAwould besakila

■ SPECIFIC_NAME— The name of the stored routine containing this parameter

■ ORDINAL_POSITION— The position of the parameter in the parameter list for the storedroutine The first parameter has a value of 1, the second has a value of 2, and so on Thereturn value of a stored function has a value of 0

■ PARAMETER_MODE— This value isNULLfor the return value of a stored function,INfor

an input parameter of a stored routine,OUTfor an output parameter of a stored procedure,andINOUTfor a parameter that is used for both input and output

■ PARAMETER_NAME— The name of the parameter The value isNULLfor the return value

of a stored function

Trang 25

■ DATA_TYPE— The data type of the parameter, such asINT,CHAR, orENUM.

■ CHARACTER_MAXIMUM_LENGTH— The maximum number of characters allowed by thedata type of the parameter For example, a parameter data type defined asVARCHAR(64)

has aCHARACTER_MAXIMUM_LENGTHof 64 This is only valid for string data, whichincludesCHAR,VARCHAR,TEXT,BLOB,SET, andENUMtypes

■ CHARACTER_OCTET_LENGTH— The maximum octet size allowed by the data type of theparameter.CHARACTER_OCTET_LENGTHis the same asCHARACTER_MAXIMUM_LENGTH

except when multi-byte character sets are used (such asutf8)

■ NUMERIC_PRECISION— The number of digits used to define the data type of theparameter Example values are 10 for anINTand 5 for aSMALLINT This is only valid fornumeric data types, includingINT,DECIMAL, andFLOAT For non-numeric data types,the value isNULL

■ NUMERIC_SCALE— This value isNULLfor non-numeric data types For numeric datatypes includingINT,DECIMAL, andFLOAT, this value is equivalent to the number of digitsafter the decimal point, which is 0 for data types that are integers

■ CHARACTER_SET_NAME— The default character set for this parameter This is only validfor non-binary string data, which includesCHAR,VARCHAR,TEXT,SET, andENUMtypes

■ COLLATION_NAME— The default collation for this parameter This is only valid fornon-binary string data, which includesCHAR,VARCHAR,TEXT,SET, andENUMtypes

Sample values areutf8_general_ci,latin1_bin, andlatin1_swedish_ci

■ DTD_IDENTIFIER— The definition of the parameter For example, a function thatdefines the return value asRETURNS decimal(5,2)has aDTD_IDENTIFIERof

decimal(5,2)

■ ROUTINE_TYPE— The type of stored routine, eitherFUNCTIONorPROCEDURE Added inMySQL version 6.0.5

TheSHOW CREATE PROCEDURE,SHOW CREATE FUNCTIONstatements, and themysql.proc

system table have some details about stored routine parameters TheSHOW CREATEstatementscontain the definition of the parameters, and themysql.proctable has theparam_listfield,which contains the part of the routine definition that defines the parameters Themysql.proc

table contains one row per stored routine, so thePARAMETERSsystem view is the only way toget information about an individual parameter

■ EVENT_SCHEMA— The name of the database that the event belongs to, such assakila

■ EVENT_NAME— The name of this event

Ngày đăng: 17/10/2013, 21:15

TỪ KHÓA LIÊN QUAN