mysql> create database mydb4; Query OK, 1 row affected (0.01 sec) mysql> use mydb4; Database changed mysql> create table stu_info( -> stu_id int primary key auto_increment comment '学号', -> stu_name varchar(30) not null comment '姓名', -> stu_age tinyint not null check (stu_age >= 18), -> stu_gender char(1) not null default 'M' check (stu_gender in ('F', 'M')) -> ); Query OK, 0 rows affected (0.04 sec)
创建完成后,就可以进行添加数据的操作了(表的名字是自己起的),记得和下面的名字匹配上就行。
insert into stu_info values(10001,'张三',18,'M');
insert into stu_info(stu_name,stu_age) values('李四',19);
insert into stu_info(stu_name,stu_age) values('王五',22);
以下仅供参考:
insert into stu_info[(stu_id,stu_gender)] values('王五',22)[,(10003,'F')];
完成后,即可查看表中的数据
mysql> select * from stu_info; +--------+----------+---------+------------+ | stu_id | stu_name | stu_age | stu_gender | +--------+----------+---------+------------+ | 10001 | 张三 | 18 | M | | 10002 | 李四 | 19 | M | | 10003 | 王五 | 22 | M | +--------+----------+---------+------------+ 3 rows in set (0.00 sec)
上一篇:SQL sever中用户管理