常用sql语句范例
1、打开sql2008,默认windows身份认证

2、展开系统数据库,我们以【master】数据库中的表作为范例

3、点击【新建查询】打开查询窗口

1、在数据表上单击右键【选择前1000行】,会自动生成sql语句,并显示查询结果

2、use master——为了防止对其它数据库的误操作我们使用“use” select * from spt_values——查询spt_values表中所有数据

3、点击【执行】或者按快捷键【F5】执行选中的sql语句
select * from spt_values order by number——按字段number排序默认为升序
select * from spt_values order by number desc按字段number降序排列

4、select name as 姓名,number as 编号,type as 类型,low,high,status as 状态 from spt_values order by number desc——将查询的列名替换为汉字

5、注释采用“--”双横线
select name as 姓名,number as 编号,type=(case type when 'D2' then '重要' when 'EOB' then '一般' end),low,high,status as 状态 from spt_values order by number desc——将查询结果替换为相应文字

1、在删除之前建议先查询一下需要删除的数据
select * from spt_values where type='A'
delete from spt_values

2、在删除之前也可以新建一个表[A_spt_values]用于备份即将删除的数据
SELECT * into A_spt_values from spt_values where type='A'
