mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| snow |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql> set names gbk;
Query OK, 0 rows affected (0.00 sec)
mysql> use snow;
Database changed
mysql> create table yg;
ERROR 1113 (42000): A table must have at least 1 column
mysql> create table yg
-> (
-> 工号 char(6) not null,
-> 姓名 char(10) not null,
-> 出生日期 date not null,
-> 性别 char(2) not null
-> ) engine = innodb;
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE TABLE hzyg LIKE yg;
Query OK, 0 rows affected (0.00 sec)
mysql> describe hzyg;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| 工号 | char(6) | NO | | NULL | |
| 姓名 | char(10) | NO | | NULL | |
| 出生日期 | date | NO | | NULL | |
| 性别 | char(2) | NO | | NULL | |
+----------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> create table csyg as select 工号,姓名,性别 from yg;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> describe csyg;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| 工号 | char(6) | NO | | NULL | |
| 姓名 | char(10) | NO | | NULL | |
| 性别 | char(2) | NO | | NULL | |
+-------+----------+------+-----+---------+-------+
3 rows in set (0.00 sec)
SQL实验三 创建1数据库和表结构
于 2024-05-01 11:39:02 首次发布