时间:2021-07-01 10:21:17 帮助过:21人阅读
语法:
alter table 表名 add(添加)|modify(修改)|drop(删除) 列名 类型;
添加列:h_skill 为字符类型
alter table hero add h_skill varchar(10);
修改列:h_skill修改本属性不能为空
alter table hero modify h_skill varchar(10) not null;
drop table 表名;
desc 表名;
mysql> desc hero; +---------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+----------------+ | h_id | int(11) | NO | PRI | NULL | auto_increment | | h_name | varchar(10) | NO | | NULL | | | h_skill | varchar(10) | NO | | NULL | | +---------+-------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec)
6、更改表名称
rename table 原表名 to 新表名;
7、查看边的创建语句
show create table 表名
例如:
mysql> show create table hero; +-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | hero | CREATE TABLE `hero` ( `h_id` int(11) NOT NULL AUTO_INCREMENT, `h_name` varchar(10) NOT NULL, `h_skill` varchar(10) NOT NULL, PRIMARY KEY (`h_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 | +-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
insert into 表名(列1,...) values(值1,...);
例如:
insert into hero(h_id,h_name,h_skill) values(1,‘韩信‘,‘裂天爆斩‘);
主键列是自动增长,但是在全列插入时需要占位,通常使用0,插入成功后以实际数据为准
select * from 表名
例如:
mysql> select * from hero; +------+--------+--------------+ | h_id | h_name | h_skill | +------+--------+--------------+ | 1 | 韩信 | 裂天爆斩 | +------+--------+--------------+ 1 row in set (0.00 sec)
例如:
update hero set h_skill=‘真裂天爆斩‘ where h_id=1;
mysql> select * from hero; +------+--------+-----------------+ | h_id | h_name | h_skill | +------+--------+-----------------+ | 1 | 韩信 | 真裂天爆斩 | +------+--------+-----------------+ 1 row in set (0.00 sec)
delete from 表名 where 条件
例如:
mysql> delete from hero where h_id=1; Query OK, 1 row affected (0.01 sec) mysql> select * from hero; Empty set (0.00 sec)
python数据库-MySQL数据库的增删改查基本操作(49)
标签:idt show desc sql数据库 插入 charset 浮点 rem time