1.创建一个名为mydb的数据库
mysql> show database mydb;
查询
mysql> show database mydb;
2.创建一个学生信息表
mysql> create table mydb.student_informtion(
-> student_id int unsigned not null primary key, //非空(不允许为空),为这个表的主键 --- 学号
-> student_name varchar(64) not null, //姓名
-> student_gender char(1) not null, //性别
-> student_age int unsigned not null, //年龄
-> student_native text(3), //籍贯
-> student_face tinytext //面貌
-> )
-> engine=innodb; //指定储存引擎为innodb
query ok, 0 rows affected (0.01 sec)
查询所建的表
mysql> show tables from mydb;
查询表结构内容
mysql>desc student_informtion;
3. 修改列类型
mysql> alter table
-> student_informtion modify
-> student_gender varchar(1);
mysql>desc student_informtion;
4.增加行
mysql> alter table
-> student_informtion add
-> student_home char(1);
mysql>desc student_informtion;
5.删除行
mysql> alter table student_informtion
-> drop
-> student_home;
mysql>desc student_informtion;
6.更改列名
mysql> alter table student_informtion
-> change
-> student_id
-> student_id1
-> int;
mysql>desc student_informtion;
7.更改表名
mysql> alter table student_informtion
-> rename
-> student_info;
mysql> desc student_info;
mysql> show tables from mydb;
到此这篇关于mysql建表和增添改查的文章就介绍到这了,更多相关mysql建表和增添改查内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论