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)文章来源:https://www.toymoban.com/news/detail-630709.html
查询所建的表
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;
文章来源地址https://www.toymoban.com/news/detail-630709.html
到了这里,关于MySQL建表和增添改查的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!