1.按姓氏筆畫排序:
Select * From TableName Order By CustomerName Collate Chinese_PRC_Stroke_ci_as //從少到多
2.數據庫加密:
select encrypt('原始密碼') select pwdencrypt('原始密碼')
select pwdcompare('原始密碼','加密後密碼')= 1--相同;否則不相同 encrypt('原始密碼')
select pwdencrypt('原始密碼')
select pwdcompare('原始密碼','加密後密碼')= 1--相同;否則不相同
3.取回表中字段:
declare @listvarchar(1000), @sql nvarchar(1000)
select @list=@list+','+b.name from sysobjects a,syscolumns b wherea.id=b.id and a.name='表A' set @sql='select '+right(@list,len(@list)-1)+'from 表A' exec (@sql)
4.查看硬盤分區:
EXEC master..xp_fixeddrives
5.比較A,B表是否相等:
if (selectchecksum_agg(binary_checksum(*)) from A)
=
(select checksum_agg(binary_checksum(*)) from B) print '相等' else print '不相等'
6.殺掉所有的事件探察器進程:
DECLARE hcforeach CURSORGLOBAL FOR SELECT 'kill '+RTRIM(spid)
FROM master.dbo.sysprocesses WHERE program_name IN('SQL profiler',N'SQL 事件探查器') EXEC sp_msforeach_worker '?'