(学python的注意了)SQL语句要以分号结尾;
(学python的注意了)SQL语句要以分号结尾;
(学python的注意了)SQL语句要以分号结尾;
查看所有数据库 show databases;
创建数据库 create database 库名 charset=utf8;
(如果你使用charset=utf8
则有可能不支持中文)
使用数据库 use 库名;
(在使用一个库的时候可以使用此命令直接切换到其他的库中)
查看当前使用的数据库 select database();
删除数据库 drop database 库名 ;
查看数据库编码 show create database 库名;
展示该库中所有的表 show tables;
create tabale 标名(id int primary key not null auto_increment,name varchar(30))
如果一个表中的字段很多都写在一行里很如也写乱,所有如下,在不输入分号的时候可以无限制按回车换行
create table students(id int unsigned not null primary key auto_increment, # 设置id 为无符号int类型 不能为空 并且设置为主键 主键自动增长 -> name varchar(30), # name字段 字符串类型最大为30个字节-> age tinyint unsigned default 0, # age字段无符号小int类型(0-255)-> high decimal(5,2), # high 小数类型 共5位数字,小数点后面有2位-> gender enum("男","女","未知") default "未知", # 枚举类型,默认值必须在枚举类型中-> cls_id int unsigned # 无符号int类型-> ); # 最后补上后括号和分号结束
alter table 表名 add 列名 类型 [after 字段名];
中括号中的内容可有可无alter table students add birthday datetime after name;
-- 在students表中添加一个birthday字段,类型为datatime,该字段会被插入到name字段后面,如果不加after name 则默认将新字段加在末尾
alter table 表名 modify 列名 类型及约束;
用法如下:alter table students modify birthday date; # 修改sutdents表中的birthday字段的类型为data
alter table 表名 change 原名 新名 类型及约束;
用法如下:alter table students change birthday birth date default "2000-01-01";
# 将students表中的birthday字段修改成birth (注:修改名称时元字段的所有约束此处都要写上)
alter table 表名 drop 列名;
alter table students drop high; # 删除表中的high字段
删除表结构
drop table 数据表;
执行命令后该表将直接物理删除,慎用
重命名表
rename table 旧表名 to 新表名;
rename table students to student; # 修改表名为student
truncate 表名;
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态