53魔力发布网,提供最好最新的开机信息

查看完整版本: mysql常用用法

xuyaoxy 2008-4-25 09:46

mysql常用用法

[color=Red]一、Create 用法:(建库,建表,建视图,建索引)[/color]
1、建  库:Create  database  数据库名
2、建  表:Create  table     表名
3、建视图:Create  view     视图名  AS  查询语句
4、建索引:Create  index    索引名 on 表名(列名)
[color=Red]二、Drop  用法:(删数据库,删表,删视图,删索引)[/color]
1、删除数据库:Drop  database  数据库名
2、删除表:    Drop  table      表名
3、删除视图:  Dorp  view      视图名
4、删除索引:  Drop  index     表名.索引名
[color=Red]三、Alter  用法:[/color]
1、表中数据结构:Alter table 表名 alter column 列名varchar(8)
2、添加字段列:  Alter table 表名 add  列名  varchar(4)
3、删除字段列:  Alter table 表名 drop column 列名
4、修改视图:    Alter view  视图名
[color=Red]四、Update  用法:[/color]
1、表中的资料:  Update  表名  set  列名= 表达式  where  条件
[color=Red]五、Delete  用法:[/color]
1、删除表中资料:Delete  from 表名  where 条件表达式
[color=Red]六、Insert into 用法 :[/color]
1、Insert  into  表名  values (表达式)
2、Insert  into  表名  (列名,列名)  values (表达式)
3、Insert  视图名   values (表达式)
[color=Red]七、select 查询语句:[/color]
1、查询表中所有资料:Select *from 表名
2、查询视图所有资料:Select *from  视图名
3、查询部分列:      Select  列名,列名  from  表名
4、按条件查询:      Select  *from  表名where  条件
5、查询部分列并修改列名:Select  列名  修改的列名  from  表名  
6、联接查询:        Select  *from 表名inner join  表名  on  条件表达式  
7、左外联接:        Select  *from 表名 left outer join 表名 on  条件表达式
8、右外联接:        Select  *from 表名 right outer join 表名 on  条件表达式
9、子 查 询(可嵌套):Select 列名 from 表名  where 列名 in
(Select 列名 from 表名 where  条件)
10、查看索引:      Exec  se_helpindex  表名
[color=Red]八、Top  语句[/color]
1、返回前10  行内容:Select  top  10 *from 表名
2、返回前10%的内容:Select  top  10 percent  * from 表名
实体完整性:①主健约束   列名  类型  primary  key
②唯一约束   列名  类型  unique  
③标识列     列名  类型  identity (  )
域 完整 性:①默认值约束   列名  类型  default 默认值   
②检查约束     列名  类型  check (条件)
③非空属性     列名  类型  not null
引用完整性:外健引用   foreign key references
统 计函 数: 求和sum( ),平均值avg ( ),最小值min ( ),最大值max ( ),返回行数count ( )
消除重复行:select  distinct (列名)  from 表名
ordey by 排序:  升序ASC   降序 DESC
group by 分组
having   筛选  和group by 一起使用

yzg2007 2008-4-25 13:14

沙发! 看完了!顶 :|:20 :|:20 :|:20

xuyaoxy 2008-4-26 07:29

其实这个很实用~而且还很简单.看看基本就会了..
页: [1]
查看完整版本: mysql常用用法
妖城魔力欢迎您