MySQL初步

                                                             MySQL初步

             

            好久没有看数据库方面的东西了,现在需要做一些简单的复习回顾,所选用的数据库是阿里云提供的RDS型数据库,MySQL5.5,所有操作可以直接利用其中的iDB Cloud操作平台进行操作。

            首先是创建database。create database zxddb;使用该数据库use zxddb;在该数据库下建表:删除该数据库:drop database zxddb;我们知道,MySQL有多种存储引擎,可以用show engines;命令查看。在RDS中,我们利用show variables like 'storage_engine';指令可以查看其默认的存储引擎为:InnoDB。

             CREATE的用法:接下来是创建表,如果在建表的时候不设置主键,则不能对表进行编辑工作。

create table gamespecie(id int primary key,name varchar(20),species varchar(20),players int);

            DROP的用法:删除表:

drop table gamespecie;

            INSERT的用法:在表中添加数据:

insert into gamespecie(id,game,species,players)values(0,'DOTA','STARCRAFT',100);
insert into gamespecie(id,game,species,players)values(1,'STARCRAFT','RTS',10);
insert into gamespecie(id,game,species,players)values(2,'MARIO','SIG',1000);

             则可得到下图:


             UPDATE的用法:修改表中的数据,将key为0的数据中的species修改为moba。结果影响了一行。修改成功。STARCRATF变为MOBA。

update gamespecie set species ='MOBA' where species ='STARCRAFT';         

             SELECT的用法:查找表中的数据,结果为:

select game from gamespecie;
select players from gamespecie where game ='DOTA';

 

              ORDER BY的用法:按照某一列从小到大的规则查找

select game,species,players from gamespecie order by players;

               结果为:其中order by 后面的那一列可以用具体它是第几列代替,也就是说可以把players换成3;

               AND和OR的用法:利用or和and可以将多个条件组合起来形成新的选择条件。

select game from gamespecie where id =1 or id=2;
select game from gamespecie where id =1 and 1=1;

结果分别如下:

               LIMIT的用法:从表中取出记录中的前几条:这条指令相当于SQL语句中的TOP。

select * from gamespecie limit 2;

 结果为:

               LIKE用法:选出符合某一pattern的数据,下面这句话是选出species以s开头的game

select game where species like 's%';
 结果为:
                To be continued...
 

猜你喜欢

转载自zju-sparkzhx.iteye.com/blog/2102961