随笔分类 - SQLServer专栏
SQL相关的知识技巧
摘要:select 'ALTER TABLE [' + b.name + '] NOCHECK CONSTRAINT ' + a.name +';' as 禁用约束 from sysobjects a ,sysobjects b where a.xtype ='f' and a.parent_obj = b.idselect 'ALTER TABLE [' + b.name + '] CHECK CONSTRAINT ' + a.name +';' as 启用约束 from sysobje
阅读全文
摘要:select total_elapsed_time / execution_count 平均时间,total_logical_reads/execution_count 逻辑读,usecounts 重用次数,SUBSTRING(d.text, (statement_start_offset/2) + 1, ((CASE statement_end_offset WHEN -1 THEN DATALENGTH(text) ELSE statement_end_offset END - statement_start_offset)/2) + 1) 语句执行 from sys.dm_exec_..
阅读全文
摘要:declare @dbid intselect @dbid = db_id()select objectname=object_name(s.object_id), s.object_id, indexname=i.name, i.index_id , user_seeks, user_scans, user_lookups, user_updatesfrom sys.dm_db_index_usage_stats s, sys.indexes iwhere database_id = @dbid and objectproperty(s.object_id,'IsUserTable&
阅读全文
摘要:直接上代码。。。。select CONVERT(varchar(10), CONVERT(datetime, '2011-12-1')+d,120) as [time] from ( select top (datediff(day,'2011-12-1','2011-12-31')+1) row_number() over(order by getdate())-1 d from sys.objects ) as a
阅读全文
摘要:GO/****** Object: StoredProcedure [dbo].[SinaBlog_Album_CreateAlbum] Script Date: 06/15/2011 17:40:21 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author: <grokyao>-- Create date: <2011-06-15>-- Description: <将表中数据倒为Insert语句>
阅读全文
摘要:Sql里获取随机的日期时间。 --设置起始日期 declare @starttime datetime --设置结束日志 declare @endtime datetime set @starttime='2010-01-01' set @endtime = '2010-02-01' declare @ctime datetime declare @count int --得到该日期段内随机的某一天日期 select @ctime= dateadd(SECOND,convert(int,(rand()*datediff(SECOND,@starttime,@en
阅读全文
摘要:insert into TABLENAME select *from OPENROWSET('SQLOLEDB','SERVER=10.25.65.32;uid=用户;pwd=密码;Database=库名','select * from 表名') as a此语句可用于本地sql脚本操作外部服务器的结果集使用。
阅读全文

浙公网安备 33010602011771号