MySQL建表和增添改查

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;

相关推荐
夜泉_ly2 小时前
MySQL -安装与初识
数据库·mysql
qq_529835353 小时前
对计算机中缓存的理解和使用Redis作为缓存
数据库·redis·缓存
月光水岸New6 小时前
Ubuntu 中建的mysql数据库使用Navicat for MySQL连接不上
数据库·mysql·ubuntu
狄加山6756 小时前
数据库基础1
数据库
我爱松子鱼6 小时前
mysql之规则优化器RBO
数据库·mysql
chengooooooo6 小时前
苍穹外卖day8 地址上传 用户下单 订单支付
java·服务器·数据库
Rverdoser7 小时前
【SQL】多表查询案例
数据库·sql
Galeoto7 小时前
how to export a table in sqlite, and import into another
数据库·sqlite
人间打气筒(Ada)8 小时前
MySQL主从架构
服务器·数据库·mysql
leegong231118 小时前
学习PostgreSQL专家认证
数据库·学习·postgresql