MySQL第四课
CREATE TABLE biao(
name VARCHAR(20) PRIMARY KEY,
age INT(11) NOT NULL,
sex CHAR(11)DEFAULT 1,
love VARCHAR(11)
);
Query OK, 0 rows affected
此时name设置了主键约束,age设置了非空约束,sex默认值为一
查看: DESC biao;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name | varchar(20) | NO | PRI | NULL | |
| age | int(11) | NO | | NULL | |
| sex | char(11) | YES | | 1 | |
| love | varchar(11) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set
添加数据:
INSERT INTO biao (name,age,sex,love) VALUES ("张三",41,"男","e");
Query OK, 1 row affected
查看:SELECT*FROM biao;
+------+-----+-----+------+
| name | age | sex | love |
+------+-----+-----+------+
| 张三 | 41 | 男 | e |
+------+-----+-----+------+
1 row in set
INSERT INTO biao VALUES ("张",40,"男","em");
Query OK, 1 row affected
SELECT*FROM biao;
+------+-----+-----+------+
| name | age | sex | love |
+------+-----+-----+------+
| 张三 | 41 | 男 | e |
| 张 | 40 | 男 | em |
+------+-----+-----+------+
2 rows in set
INSERT INTO biao (sex) VALUES ("男");
Query OK, 1 row affected
SELECT*FROM biao;
+------+-----+-----+------+
| name | age | sex | love |
+------+-----+-----+------+
| 张三 | 41 | 男 | e |
| 张 | 40 | 男 | em |
| | 0 | 男 | NULL |
+------+-----+-----+------+
3 rows in set
INSERT INTO biao(name,age,sex,love) VALUES("李四",39,"女","ex"),("王五",38,"男","van"),("甲",20,"男","emm");
Query OK, 3 rows affected
Records: 3 Duplicates: 0 Warnings: 0
SELECT*FROM biao;
+------+-----+-----+------+
| name | age | sex | love |
+------+-----+-----+------+
| 张三 | 41 | 男 | e |
| 张 | 40 | 男 | em |
| | 0 | 男 | NULL |
| 李四 | 39 | 女 | ex |
| 王五 | 38 | 男 | van |
| 甲 | 20 | 男 | emm |
+------+-----+-----+------+
6 rows in set
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341