--查询从10行到20行之间的数据
select * from (select top 20 * from 表名) as A where A.FID not in (select top 10 B.FID from 表名 as B)
--查询数据带编号
select row_number()over(order by FID )as Row,* from 表名
---------------
-- 判断要创建的表名是否存在
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
-- 删除表
drop table [dbo].[表名]
GO
---------------
--判断要创建临时表是否存在
If Object_Id('Tempdb.dbo.#Test') Is Not Null
Begin
print '存在'
End
Else
Begin
print '不存在'
End
---------------
-- 判断要创建的存储过程名是否存在
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[存储过程名]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
-- 删除存储过程
drop procedure [dbo].[存储过程名]
GO
---------------
-- 判断要创建的视图名是否存在
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[视图名]') and OBJECTPROPERTY(id, N'IsView') = 1)
-- 删除视图
drop view [dbo].[视图名]
GO
---------------
-- 判断要创建的函数名是否存在
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[函数名]') and xtype in (N'FN', N'IF', N'TF'))
-- 删除函数
drop function [dbo].[函数名]
GO
if col_length('表名', '列名') is null
print '不存在'
select 1 from sysobjects where id in (select id from syscolumns where name='列名') and name='表名'
--SQL Server 2008新数据类型
SELECT
CAST('2007-05-08 12:35:29. 1234567 +12:15' AS time(7)) AS 'time'
,CAST('2007-05-08 12:35:29. 1234567 +12:15' AS date) AS 'date'
,CAST('2007-05-08 12:35:29.123' AS smalldatetime) AS'smalldatetime'
,CAST('2007-05-08 12:35:29.123' AS datetime) AS 'datetime'
,CAST('2007-05-08 12:35:29. 1234567 +12:15' AS datetime2(7)) AS 'datetime2'
,CAST('2007-05-08 12:35:29.1234567 +12:15' AS datetimeoffset(7)) AS 'datetimeoffset';
--查询从10行到20行之间的数据select * from (select top 20 * from 表名) as A where A.FID not in (select top 10 B.FID from 表名 as B)--查询数据带编号select row_number()over(order by FID )as Row,* from 表名-----------------