MySQL for Linux on POWER 数据库创建简介
2008-01-18 11:06:45 来源:WEB开发网注意创建表的顺序。被参照的表必须在进行参照的表之前创建。如果您将表的类型指定为 InnoDB,那么这个顺序就不会那么重要。不过,参照完整性将得不到保证。
要深入了解 MySQL 参照完整性,请参考 MySQL 产品文档中关于外部关键字的部分。
要通过上述文件执行 SQL 语句,您只需要在命令行中将其传递给 mysql,就可以读取文件,类似这样:
mysql -u username < filename
要深入了解 MySQL 的批处理使用模式,请参考 MySQL 产品文档。
要查看您创建的表结构,请输入下面的命令:
mysql> SHOW TABLES;
+-----------------------+
| Tables_in_CONTRACTING |
+-----------------------+
| EMPLOYEE |
| JOB |
| ORDERFORM |
| PROJECT |
+-----------------------+
4 rows in set (0.00 sec)
mysql> DESCRIBE JOB;
+---------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------------+------+-----+---------+-------+
| JOB_CODE | int(11) | | PRI | 0 | |
| JOB_NAME | mediumtext | | | | |
| JOB_HOUR_CHRG | decimal(10,2) | | | 0.00 | |
+---------------+---------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> DESCRIBE EMPLOYEE;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| EMP_SSN | varchar(9) | | PRI | | |
| EMP_LNAME | varchar(50) | | | | |
| EMP_FNAME | varchar(50) | | | | |
| JOB_CODE | int(11) | | MUL | 0 | |
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> DESCRIBE PROJECT;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| PRJ_NUM | int(11) | | PRI | 0 | |
| PRJ_NAME | varchar(50) | | | | |
| EMP_SSN | varchar(9) | | MUL | | |
+----------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)
mysql> DESCRIBE ORDERFORM;
+---------------+---------------+------+-----+------------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------------+------+-----+------------+-------+
| ORD_NUM | int(11) | | PRI | 0 | |
| ORD_DATE | date | | | 0000-00-00 | |
| ORD_HOURS | smallint(6) | | | 0 | |
| ORD_CHRG_HOUR | decimal(10,2) | | | 0.00 | |
| ORD_CHARGE | decimal(10,2) | | | 0.00 | |
| PRJ_NUM | int(11) | | MUL | 0 | |
| EMP_SSN | char(9) | | MUL | | |
+---------------+---------------+------+-----+------------+-------+
7 rows in set (0.00 sec)
更多精彩
赞助商链接