时间:2021-07-01 10:21:17 帮助过:2人阅读
| 1 |
mysql -h10.20.66.32 -uroot -p123456
|
-h后面是mysqlServer所在地址,-u后面是用户名,-p后面是密码
| 1 |
show databases;
|

| 1 |
use test;
|
| 1 |
show tables;
|

| 1 |
desc winton
|

| 1 2 3 4 |
create table t1(
id int not null primary key,
name char(20) not null
);
|
语法 create table 表名称( 字段名 字段名类型 字段描述符,字段名 字段类型 字段描述符);
| 1 |
alter table t1 add(score int not null);
|
语法:alter table 表明称 add(字段名 类型 描述符);
| 1 |
alter table t1 drop column score;
|
语法:alter table 表名 drop colunm 字段名,drop colunm 字段名;
| 1 |
alter table t1 change name score int not null;
|
语法:alter table 表名 change 旧字段名 新字段名 新字段描述符
| 1 |
insert into winton values(001,‘zww‘),(002,‘rs‘);
|
语法:insert into 表名 values(字段1值,字段2值,……),(字段1值,字段2值,……);
| 1 |
insert into winton(id) values(004);
|

查看插如后的结果,如上图所示。
语法:insert inton 表名(字段名) values(值一),(值二);
| 1 |
select * from t1;
|
语法:select * from 表名;
| 1 |
select id from t1;
|
语法:select 字段一,字段二 from 表名;
| 1 |
select t1.id,t1.score,winton.name from t1,winton;
|

语法:select 表一字段,表二字段,表三字段,…… from 表一,表二,表三,……;
| 1 |
select * from t1 where socre>90;
|
语法:select 字段1,字段2 from 表名 where 条件;
| 1 |
select t1.id,t1.score,winton.name from t1,winton where t1.id=winton.id;
|

语法:select 表一字段,表二字段 from 表一,表二 where 条件;
| 1 |
select name from winton where id=(select id from t1 where score=90);
|

语法:select 字段一,字段二…… from 表名 where 条件(查询);
| 1 |
(select id from t1 )union(select id from winton);
|

| 1 |
select id from t1 where id in (select id from winton);
|

| 1 |
delete from winton where id=4;
|
语法:delete from 表名 where 条件;
| 1 |
update t1 set score=69 where id=2;
|
语法:update 表名 set 更改的字段名=值 where 条件;
| 1 |
select sum(score) from t1;
|
注:sum(字段) 对字符串和时间无效
| 1 |
select avg(score) from t1;
|
注:avg(字段)对字符串和时间无效
| 1 |
select count(*) from t1;
|
注:count(字段名)不包含NULL;

| 1 |
select max(name) from winton;
|
注:max(colunm)返回字母序最大的,返回数值最大的
| 1 |
select min(name) from winton;
|
注:min(colunm)返回字母序最小值,返回数值最小值
| 1 |
select distinct name from winton;
|
| 1 |
select * from winton limit 2;
|
| 1 |
select * from winton order by name;
|
注:默认是升序
| 1 |
slelect * from winton order by name desc;
|
| 1 |
select * from winton order by name asc;
|
| 1 |
select name from winton group by name;
|
恩,基本能想起来的就值么多了,都是最基础,最常用的一些。
原文出处:http://blog.csdn.net/wenwen091100304/article/details/49368019
SQL基础语句汇总
标签: