是時候復習一波SQL語句的語法了,無需太深,但總得會用啊。
一步步由淺到深,這里用的都是mysql做的。
mysql -h10.20.66.32 -uroot -p123456
-h后面是mysqlServer所在地址,-u后面是用戶名,-p后面是密碼
show databases;
use test;
show tables;
desc winton
create table t1( id int not null primary key, name char(20) not null );
語法 create table 表名稱( 字段名 字段名類型 字段描述符,字段名 字段類型 字段描述符);
drop table test;
語法:drop table 表名稱;
alter table t1 add(score int not null);
語法:alter table 表明稱 add(字段名 類型 描述符);
alter table t1 drop column score;
語法:alter table 表名 drop colunm 字段名,drop colunm 字段名;
alter table t1 change name score int not null;
語法:alter table 表名 change 舊字段名 新字段名 新字段描述符
insert into winton values(001,'zww'),(002,'rs');
語法:insert into 表名 values(字段1值,字段2值,……),(字段1值,字段2值,……);
insert into winton(id) values(004);
select * from t1;
語法:select * from 表名;
select id from t1;
語法:select 字段一,字段二 from 表名;
select t1.id,t1.score,winton.name from t1,winton;
select * from t1 where socre>90;
語法:select 字段1,字段2 from 表名 where 條件;
select t1.id,t1.score,winton.name from t1,winton where t1.id=winton.id;
select name from winton where id=(select id from t1 where score=90);
(select id from t1 )union(select id from winton);
select id from t1 where id in (select id from winton);
delete from winton where id=4;
語法:delete from 表名 where 條件;
update t1 set score=69 where id=2;
語法:update 表名 set 更改的字段名=值 where 條件;
select sum(score) from t1;
注:sum(字段) 對字符串和時間無效
select avg(score) from t1;
注:avg(字段)對字符串和時間無效
select count(*) from t1;
注:count(字段名)不包含NULL;
select max(name) from winton;
注:max(colunm)返回字母序最大的,返回數(shù)值最大的
select min(name) from winton;
注:min(colunm)返回字母序最小值,返回數(shù)值最小值
select distinct name from winton;
select * from winton limit 2;
select * from winton order by name;
注:默認是升序
slelect * from winton order by name desc;
select * from winton order by name asc;
select name from winton group by name;
create index wintonIndex on winton (name);
語法:create index 索引名稱 on 表名 (字段一,字段二,……);
create unique index wintonIndex on winton (id);
語法:create unique index 索引名 on 表名 (字段一,字段二,……);
ps:unique index 要求列中數(shù)據(jù)唯一,不能出現(xiàn)重復。
drop index wintonIndex on winton;
語法: drop index 索引名 on 表名;
聯(lián)系客服