mysql 一看就会 基本语法

本文详细介绍如何使用SQL进行基本的数据库操作,包括创建、删除、查询、更新等,并提供了实际的例子来帮助理解各种命令的用法。

创建表 

create table <表名>(
 <字段名>  类型(长度) not null primary key auto_increment, **主键
 name char(20) not null,  
 sex int(4) not null default '0', **默认键
 degree double(16,2)

)

 

删除表

drop table <表名>;

清空表

delete from <表名>;

 

插入数据

insert into <表名> [( <字段名1>[,..<字段名n > ])] values ( 值1 )[, ( 值n )]

 

查询表

select <字段1,字段2,...> from < 表名 > where < 表达式 >

查询表的前几个字段

select * from MyClass order by id limit 0,2;

查询字段总和

select sum('字段名') from 表名

 查询字段 按照升序降序排列

 降序:select  *  from   表名   where  表达式   order by  字段名  desc

 升序:select  *  from   表名   where  Putout=true   order by time  asc

 

删除表

delete from 表名 where 表达式

 

修改表

update 表名 set 字段=新值,… where 条件

 

添加表字段

alter table 表名 add 字段 类型 其他;

    <1  主键:alter table 表名 add primary key (字段名);

    <2  唯一约束:alter table 表名 add unique 索引名 (字段名);

 

删除表字段

alter table 表名 drop 字段名

 

转载于:https://www.cnblogs.com/renyuanhao/p/6419761.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值