SELECT
name
FROM syscolumns
WHERE (id = OBJECT_ID( '表名称'))
ORDER BY colorder
FROM syscolumns
WHERE (id = OBJECT_ID( '表名称'))
ORDER BY colorder
2.筛选重复数据
SN为出现重复的字段
非重复数据:
有重复数据:
select a.*
from 表 a
where
not
exists(
select 1
from 表
where SN=a.SN
and ID!=a.ID)
有重复数据:
select a.*
from 表 a
where
exists(
select 1
from 表
where SN=a.SN
and ID!=a.ID)
3. 获取某个存储过程中的参数列表
select
'Parameter_name' = name,
'Type' = type_name(user_type_id),
'Length' = max_length,
'Prec' = case when type_name(system_type_id) = 'uniqueidentifier' then precision
else OdbcPrec(system_type_id, max_length, precision) end,
'Scale' = OdbcScale(system_type_id, scale),
'Param_order' = parameter_id,
'Collation' = convert(sysname, case when system_type_id in (35, 99, 167, 175, 231, 239)
then ServerProperty( 'collation') end)
from sys.all_parameters where object_id = object_id('你的存储过程名称')
'Parameter_name' = name,
'Type' = type_name(user_type_id),
'Length' = max_length,
'Prec' = case when type_name(system_type_id) = 'uniqueidentifier' then precision
else OdbcPrec(system_type_id, max_length, precision) end,
'Scale' = OdbcScale(system_type_id, scale),
'Param_order' = parameter_id,
'Collation' = convert(sysname, case when system_type_id in (35, 99, 167, 175, 231, 239)
then ServerProperty( 'collation') end)
from sys.all_parameters where object_id = object_id('你的存储过程名称')
4. 在结果集上 添加 行号
(只适用于 sql 2005 ):
select *, row_number()
over (
order
by [排序列])
as rownumber
from [表名]
from [表名]
5. 简单分页程序( 在 4 的基础上完成 )
select *
from (
select *, row_number()
over (
order
by [排序列])
as rownumber
from [表名]) as tmp
WHERE RowNumber between 50 and 60;
from [表名]) as tmp
WHERE RowNumber between 50 and 60;
N.等用到时再添加哈~~`
转载于:https://blog.51cto.com/kaliking/14855