|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?加入会员
x
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:aa 表名2:bb)
select a,b,c from aa where a IN (select d from bb )
4、说明:in 的使用方法
select * from table1 where a [not] in (‘值1’,’值2’,’值4’,’值6’)
5、说明:随机取出10条数据
select top 10 * from tablename order by newid()
6、说明:删除重复记录
Delete from tablename where id not in (select max(id) from tablename group by col1,col2,...)
7、说明:列出数据库里所有的表名
select name from sysobjects where type='U'
8、说明:列出表里的所有的列名
select name from syscolumns where id=object_id('TableName')
9、说明:初始化表table1,清空所有数据
truncate table table1 |
|