最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
加速你数据库和程序开发的存储过程
时间:2022-06-30 10:26:01 编辑:袖梨 来源:一聚教程网
如果你是一个数据库工作者,或者是一个代码编写者,你是否为填写那些字段烦恼呢?少还好说,如果达到几十个,你一定会被弄得昏头晕脑,一下就失去了编写代码的快乐。
好了,用以下的方法使你省略了填写字段的烦恼,一下子就能够达到编写代码的性高潮!实在是居家旅游,必备良药,胜过伟哥!
第一步,建立视图!
create VIEW Col AS
select
b.Name ColName,
b.ColID,
c.Name xColtype,
(select Name from systypes where xUserType = c.xType and xType = xUserType) ColType,/*convert user define type to system type*/
b.Length Sizes,
b.Prec Prec,
b.xScale Scale,
convert(bit,b.status&8) Nulls,
a.Name ObjectName,
a.Type ObjectType
from sysobjects A,syscolumns b,systypes c
where a.type in ('U','V','P') and a.Id=b.Id and b.Xusertype=c.Xusertype
第一步,建立存储过程!
CREATE PROCEDURE sysgetcol
@objectname Char(80)
AS
declare
@objecttype char(10)
select
@objecttype = objecttype
from COL
where objectname = @objectname
if @@ROWCOUNT = 0
begin
Print 'Internal Error(001):'
Print ' not found object :''' + Rtrim(@objectname) +'''!'
Return -1
end
select
colname,
colType types,
xColType,
sizes,
prec,
scale,
colid,
Nulls
Into #temp
from COL
where objectname = @objectname
order by colid
--PATINDEX('%pattern%', expression)
--Script object Structure
if @objecttype = 'U'
begin
select 'Create Table ' + Rtrim(@objectname) + ' ('
union all
select ' ' + Rtrim(colname) + ' ' + RTrim(xColType)+
Case xColType when 'Char' then '('+RTrim(Convert(Char(3),sizes))+')'
when 'Numeric' then '(' + RTrim(Convert(Char(3),Prec)) + ',' + RTrim(Convert(Char(3),Scale)) + ')'
when 'Varchar' then '('+RTrim(Convert(Char(3),sizes))+') '
when 'nchar' then '(' + RTrim(Convert(Char(3) ,sizes)) + ')'
when 'nvarchar' then '(' + RTrim(Convert(Char(3) ,sizes)) + ')'
好了,用以下的方法使你省略了填写字段的烦恼,一下子就能够达到编写代码的性高潮!实在是居家旅游,必备良药,胜过伟哥!
第一步,建立视图!
create VIEW Col AS
select
b.Name ColName,
b.ColID,
c.Name xColtype,
(select Name from systypes where xUserType = c.xType and xType = xUserType) ColType,/*convert user define type to system type*/
b.Length Sizes,
b.Prec Prec,
b.xScale Scale,
convert(bit,b.status&8) Nulls,
a.Name ObjectName,
a.Type ObjectType
from sysobjects A,syscolumns b,systypes c
where a.type in ('U','V','P') and a.Id=b.Id and b.Xusertype=c.Xusertype
第一步,建立存储过程!
CREATE PROCEDURE sysgetcol
@objectname Char(80)
AS
declare
@objecttype char(10)
select
@objecttype = objecttype
from COL
where objectname = @objectname
if @@ROWCOUNT = 0
begin
Print 'Internal Error(001):'
Print ' not found object :''' + Rtrim(@objectname) +'''!'
Return -1
end
select
colname,
colType types,
xColType,
sizes,
prec,
scale,
colid,
Nulls
Into #temp
from COL
where objectname = @objectname
order by colid
--PATINDEX('%pattern%', expression)
--Script object Structure
if @objecttype = 'U'
begin
select 'Create Table ' + Rtrim(@objectname) + ' ('
union all
select ' ' + Rtrim(colname) + ' ' + RTrim(xColType)+
Case xColType when 'Char' then '('+RTrim(Convert(Char(3),sizes))+')'
when 'Numeric' then '(' + RTrim(Convert(Char(3),Prec)) + ',' + RTrim(Convert(Char(3),Scale)) + ')'
when 'Varchar' then '('+RTrim(Convert(Char(3),sizes))+') '
when 'nchar' then '(' + RTrim(Convert(Char(3) ,sizes)) + ')'
when 'nvarchar' then '(' + RTrim(Convert(Char(3) ,sizes)) + ')'
相关文章
- 王者荣耀侦探能力大测试攻略 王者荣耀侦探能力大测试怎么过 11-22
- 无期迷途主线前瞻兑换码是什么 11-22
- 原神欧洛伦怎么培养 11-22
- 炉石传说网易云音乐联动怎么玩 11-22
- 永劫无间手游确幸转盘怎么样 11-22
- 无期迷途主线前瞻兑换码是什么 无期迷途主线前瞻直播兑换码介绍 11-22