您的位置:首页 > 数据库 > MySQL

Mysql 增减查询基本语句

2017-06-29 07:21 633 查看
MySQL增删改查语句

select * from xxx;

insert into xxx values();

update xxx set xx=xx where xxx=xxx and xxx=xxx;

delete from xxx where xx=xxx and xxx=xxx or……;

MySQL基本语句(增删改查,like语句)

查询:

select 字段名 from 表名;

例1:select * from tablename;//查询全部

例2:select (id,name) from tablename;//查询id,name

例3:select id as studentID from tablename;//查询id,查询出来的表的本来的字段名id变为studentID,as可省略

PS:查询时注意*好不能乱用,否则会导致数据库运行负担。最好是需要什么字段就查询什么字段

增添:

insert into tablename value(xx,xx);

例1:insert into tablename(id,name) value (xx,xx);//增加一行数据,只写了id与name

例2:insert into tablename value();//增加一行数据,括号里写全部信息,用逗号隔开

修改:

update tablename set xx=xx where xx=xx;

例1:updete tablename set id=1 where name="董磊";把name为董磊的id更改为1

例2:updete tablename set id=1 where name="董磊" or iq<10;

把name为董磊或者IQ<10的id更改为1。条件用and、or连接

删除:

delete from tablename where xx=xxx;

例1:delete from tablename;//删除表

例2:delete from tablename where id=1;//把id为1的数据删掉

like语句:

// %代表0到多个字符 

// _代表一个字符

例: selcet name from student where name like '张%'//查询student表中name以张开头的人的name

selcet name from student where name like '张_'//查询student表中name以张开头的2个字的name
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: