哈哈哈!这是一个音乐? 的今天哈哈哈哈
最近重映了哥哥的经典电影~英雄本色
来一波追忆~
1)复制表(只复制结构,源表名:a 新表名:b)
法一:select * into b from a where 1<>1
法二:select top 0 * into b from a
2)拷贝表(拷贝数据,源表名:a 目标表名:b)
insert into b(a, b, c) select d,e,f from b;
3)子查询(表名1:a 表名2:b)
select a,b,c from a where a IN (select d from b ) 或者: select a,b,c from a where a IN (1,2,3)
4)in 的使用方法
select * from table1 where a [not] in (‘值1’,’值2’,’值4’,’值6’)
5)四表联查问题:
select * from a left inner join b on a.a=b.b
right inner join c on a.a=c.c
inner join d on a.a=d.d where .....
6)前10条记录
select top 10 * form table1 where 范围
7)包括所有在 TableA 中但不在 TableB和TableC 中的行并消除所有重复行而派生出一个结果表
(select a from tableA ) except (select a from tableB) except (select a from tableC)
8)随机取出10条数据
select top 10 * from tablename order by newid()
9)删除重复记录
Delete from tablename where id not in (select max(id) from tablename group by col1,col2,...)
10)列出数据库里所有的表名
select name from sysobjects where type='U'
11)选择从10到15的记录
select top 5 * from (select top 15 * from table order by id asc) table_别名 order by id desc
12)1=1,1=2的使用,在SQL语句组合时用的较多
“where 1=1” 是表示选择全部 “where 1=2”全部不选,
文章还是蛮全面的~
大家可以点击【阅读全文】去查看呗~
”欢迎关注,嘻嘻~”