T-SQL 常用语句

1. 查看 Table 或者 Column 被那些object(存储过程、函数或View)调用.

select a.* from sysobjects a, syscomments b where a.id = b.id and b.text like '%tablename%'

2. 用其他表的字段数据更新表字段

update Table1

set Col1 = B.Col1, Col2 = B.Col2, Col3 = B.Col3

from Table1 A

join Table2 B on A.ID = B.ID

where A.Date = 20110329

3. 复制表结构

select * into b from a where 1=2

4. 两张关联表,删除主表中已经在副表中没有的信息

delete from table1 where not exists ( select * from table2 where table1.field1=table2.field1 )

5. 随机取出N(10)条记录

select top 10 * from tablename order by newid()

6. 列出表里的所有的列名

select name from syscolumns where id=object_id('TableName')

7. 取最新version的一行数据

select A.* from table A

where A.version = (select max(B.version) from table B where A.ID = B.ID )

 

转载于:https://www.cnblogs.com/bi-info/p/6554985.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值