1、判斷“表”是否存在:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->if exists (select * from sysobjects where id = object_id(N'[dbo].[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) print '存在'else print
View Code SET STATISTICS io ONSET STATISTICS time ON goselect top 100000 * from (select top 190000 * from job_job order by jobid asc ) as a order by jobid descgoset statistics profile offset statistics io offset statistics time offSET STATISTICS
舉例如下: 一張員工表tb_user,有欄位id、name、num(員工工號),則查詢id=20的員工的前一個員工和後一個員工的sql文分別是: 前一個員工:select top 1 * from tb_user where id < 20 order by id desc(加上desc,資料庫將從表末端開始查詢); 後一個員工:select top 1 * from tb_user where id > 20 order by id
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_who_lock]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)drop procedure [dbo].[sp_who_lock]GO/***************************************************************************// 建立 :
以下代碼相容SQL Server 2000。 SELECT c.[name] AS '列名', CASE WHEN t.[name] = 'DECIMAL' OR t.[name] = 'NUMERIC' THEN UPPER(t.[name]) + '(' + CAST(c.[xprec] AS VARCHAR) + ', ' + CAST(c.[xscale] AS VARCHAR) + ')' WHEN t.[name] = 'BINARY' OR t.[name] = 'CHAR'
Map SQL Server Profiler EventClass ID to its name in a saved trace tableIf you've ever worked with SQL Server profiler then you're familiar with the EventClass column in the trace. It tells you what event is being monitored for each row. When you