Home | Mirror | Search

第 5 章 DDL - Data Definition Language

目錄

1. Database
1.1. create
1.2. drop
1.3. Alter
1.4. Rename
1.5. CHARACTER
1.6. show create database
2. Table
2.1. create table ... select
2.2. modifiy table
2.3. TEMPORARY Table
2.4. Collate
2.5. CHARACTER
2.6. DEFAULT
2.7. KEY
2.7.1. PRIMARY KEY
2.8. COMMENT
3. Index
3.1. SHOW INDEX
3.2. CREATE INDEX
3.3. DROP INDEX
3.4. rebuild
4. 外鍵(Foreign Key)
4.1. FOREIGN KEY (RESTRICT)
5. View
6. Trigger
6.1. create trigger
6.2. drop trigger
6.3. show triggers
6.4. EXAMPLE
7. Partitioning
7.1. EXPLAIN PARTITIONS
7.2. SHOW CREATE TABLE
7.3. range
7.4. list
7.5. HASH
7.5.1. LINEAR HASH
7.6. 添加分區
7.7. ERROR 1503 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function

1. Database

1.1. create

Creating a UTF-8 database

CREATE DATABASE db_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
			

Create a UTF-8 database with binary UTF-8 collation.

CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_bin;
			

1.2. drop

DROP DATABASE db_name;
			

1.3. Alter

ALTER DATABASE dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
			

1.4. Rename

RENAME {DATABASE | SCHEMA} db_name TO new_db_name;
			

before 5.0 version

[neo@development ~]$ mysqldump -uroot -pchen db_old | mysql -uroot -pchen db_new
			

1.5. CHARACTER

			
ALTER DATABASE <database_name> CHARACTER SET utf8;			
			
			

1.6. show create database

			
mysql> show create database dbname;
+----------+-------------------------------------------------------------------+
| Database | Create Database                                                   |
+----------+-------------------------------------------------------------------+
| dbname   | CREATE DATABASE `dbname` /*!40100 DEFAULT CHARACTER SET utf8 */   |
+----------+-------------------------------------------------------------------+
1 row in set (0.00 sec)
			
			
comments powered by Disqus