找回密码
 立即注册

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手
1、同时增加多个字段
alter table 表名称 add (字段1,字段2);

alter table xiaoqian add(id int(3),name char(4));

2、删除指定的单个字段或者多个字段

alter table 表名称 drop 字段名称; #单个

alter table xiaoqian drop id;

alter table 表名称 drop 字段名称,drop 字段名称;#多个

alter table xiaoqian drop id,drop name;

3、删除表

drop table 表名称

drop table xiaoqian;删除xiaoqian这个表

删除后当前xiaoqian表不存在



表结构操作语言:DDL

create创建 alter增加修改的 drop删除 desc查询

4、创建表增加主键和自增长约束

create table dcs68(id int(4)primary key auto_increment,name char(10),scroe int(4));

5、给没有主键的表增加主键和自增长

alter table xiaoqian change id id int(5)primary key;

alter table xiaoqian change id id int(5)auto_increment;

6、删除主键和自增长

如果你要删除主键必须要先删除自增长约束

alter table xiaoqian change id id int(5);删除id中的自增长

alter table xiaoqian drop primary key;删除主键



如果给表中插入数据的流程:

1、在liunx交互界面先进入数据库:mysql -uroot -p123456

2、查询一下所有数据库:show databases;

3、进入到指定的数据库中:use +数据库名称如:use dcs68;进入dcs68数据库中

4、查询一下有没有可以用表:show tables;

5、如果没有你就自己创建一个:

creat table 表名称(字段 约束);

create table dcs(id int(3),name char(10),age int(4));#创建一个表名称dcs

6、表结构创建好后自己查询一下表结构:

desc dcs;查询dcs表结构

7、然后插入数据删除查询操作

insert into 插入数据

select * from 表; 查询

delete from 表 删除



表数据:(重点)

表数据操作语言:DML

增删改查:insert into ,delete from ,update set,select from

where条件表达式

1、表中增加数据:

结构:id ,name ,age ,scroe

insert into stu(id,name,age,scroe)values(1,'zhang',20,89); #增加一行数据

insert into stu values(2,'wang',19,100),(3,'lisi',20,99);#增加多行数据

insert into xiaoqian(name,age)values('zng',22),('ang',21),('wang',31);#自增长和主键同时插入多行数据

2、查询数据

select * from 表名称; 查询所有的数据

3、删除表的数据

delete from stu where id=4;#删除表中id=4的这一行的数据

delete from stu;删除整个表中的所有数据

备注:delete只能删除表数据,不能删除表结构,如需要删除表结构需要用drop table

4、删除整个表的数据:

truncate xiaoqian;

备注:truncate只能删除表数据,不能删除表结构,如需要删除表结构需要用drop table

5、修改表数据:

update 表名称 set 修改的值 where 条件指定;

update xiaoqian set name='zhang' where id=1;#把id=1这一行的姓名改为zhang

update xiaoqian set name='xiaoqian';#把所有的姓名都改为xiaoqian



and:与

两两为真为真

一真一假为假

一假一真为假

两两为假为假



or:或

两两为真为真

一真一假为真

一假一真为真

两两为假为假

where ,and ,or ,in,=,!=(讲解查询语句会讲)



查询(重点)

查询所有:

select * from 表名称;

select * from stu;查询stu表中的所有内容

通过条件查询某个条件的值:

select * from 表名称 where 条件;

select * from stu where name='xiaoqian';查询姓名是xiaoqian的所有内容

通过条件查询满足几个条件的内容:

select * from 表名称 where 条件 and 条件;

select * from stu where name='qian' and age=20;查询满足姓名是qian年纪是20的数据

大于>

select * from stu where scroe>60; 大于60分所有信息

小于>

select * from stu where scroe<60;小于60分所有信息

等于=

select * from stu where scroe=60;等于60分所有信息

大于等于>=

select * from stu where scroe>=60;大于等于60分所有信息

小于等于<=

select * from stu where scroe<=60;小于等于60分所有信息

不等于!=

select * from stu where scroe !=60;不包含60分的所有信息

in指定具体的值

select * from stu where scroe in(60,88,99);指定的值有就显示,没有就不显示

查询张三的信息,告诉张三的年纪的多少?

select * from stu where name='张三';

select age from stu where name='张三';



分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册