mysql常用语句

一.数据库操作
1.新建数据库
        >create database du_name;  //du_name是数据库名
2.查看数据库
        >show databases;
3.使用数据库
        >use du_name;   //du_name是数据库名
4.删除数据库
        >drop database du_name;
二.创建表
1.创建表
        >create table tb_name(              //tb_name是表名
        字段/列名  数据类型(长度) 约束条件, 
        字段/列名  数据类型(长度) 约束条件,
        字段/列名  数据类型(长度) 约束条件
    )约束条件;
    例;>create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..);
2.查看数据库可用表
         >show tables;
3.查看表结构
         >database tb_name;
4.复制表
         >create table tb_name2 select*from tb_name;
  部分复制
         >create table tb_name2 delect id,name from tb_name;
5.表重名
         >rename table name_old to name_new;
6.删除表
         >drop table ta_name;   //tb_name是表名
7.增加列
         >Alther table tb_name add colum col type;
8.添加主键
         >Alter table tabname add primary key(col);
9.删除主键
         >Alter table tabname drop primary key(col);

10.选择数据
          >select * from table1 where 范围;
11.插入数据
          >insert into table1(field1,field2) values(value1,value2);
12.删除表中数据
          >delete from table1 where 范围;
13.更新数据
          >update table1 set field1=value1 where 范围;
14.查找
          >select * from table1 where field1 like ’%value1%’;
15.排序
          >select * from table1 order by field1,field2 [desc];
16.总数
          >select count as totalcount from table1;
17.求和
          >select sum(field1) as sumvalue from table1;
18.平均
          >select avg(field1) as avgvalue from table1;
19.最大
           >select max(field1) as maxvalue from table1;
20.最小
           >select min(field1) as minvalue from table1;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值