zzzzy09

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

来自:https://blog.csdn.net/weixin_45527702/article/details/104437654

常规命令:

show databases;      #查看数据库中都有哪些库
create database mydb charset=utf8;   #创建mydb库
use mydb;        #选择mydb库
create table students(
    id int primary key aotu,
    name varchar(20) Not Noll,
    score float,
    birth date,
);     #创建学生表
show tables;     #查看当前库下的所有表
desc students;    #查看学生表都有哪些属性
select *  from students;    #查看学生表都有哪些成员
select database();          #查看当前所在的库
select show table 表名;     # 查看该表的属性
drop table students;        #删除学生表,指没有关联的表
drop database mydb;         #删除mydb库
delete from 表名;           #删除该表
delete from user where name='张三';    #删除user表中‘张三’这个字段

 

 

alter:针对表的字段

alter table 旧表名 rename to 新表名;    #修改表名
rename 旧表名 to 新表名;
eg:alter table scores rename grades;

alter table 表名 modify 字段名  数据类型;   #修改字段的数据类型
eg:alter table scores modify score int;

alter table 表名 change 旧字段  新字段  数据类型;   #修改字段名
eg:alter table scores change score grade int;

alter table 表名 add 新字段 数据类型;    #添加字段
eg:alter table scores add name varchar(10);

alter table 表名 drop 字段名;   #删除字段
eg:alter table scores drop address;

alter table 表名 drop foreign key 外键约束名;    #删除表的外键约束
eg:alter table scores drop foreign key name;

 

 

注意:删除关联表时,先解除关联,再进行删除。


insert插入:针对数据

insert into scores(name,school,grade,teacher) values(jack,beijing,75,wangqiang);   #单行插入
insert into scores(name,school,grade,teacher) values(jack,beijing,75,wangqiang),
                                                    (tom,xian,86,liuhan),
                                                    (alice,shanghai,69,noll);   #多行插入

update更新

update scores set name=tom;    #将scores表中name全部更新为tom】
update school set num=num+20 where address='China';  #给school表中地址为China的加20

 

posted on 2020-09-27 15:13  zzzzy09  阅读(287)  评论(0编辑  收藏  举报