如:我在主程序中输入一个信息。然后,我在SQL2000中查找该信息存贮在该数据库的哪些表及相应原字段名。
9 个解决方案
#1
不好写,你知道的信息太少了,写起来会很长,你看起来也会非常吃力,你要多多想想还知道什么信息可以提供的.
#2
研究下系统表,建议提供字段值外还提供数据类型,否则不同类型数据的比较将相当麻烦
#3
学习+++++++
#4
查系统表, 用动态SQL吧
#5
需求不足,难实现!
field的类型都没有规定.写起来麻烦
field的类型都没有规定.写起来麻烦
#6
如果字段类型为:varchar
#7
--建两个表来测试一下
CREATE TABLE [dbo].[SPFP] (
[OF_DH] [int] NOT NULL ,
[OF_HH] [int] NOT NULL ,
[OF_ZFZT] [bit] NOT NULL ,
[OF_GXSJ] [datetime] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[SPPJ] (
[OF_DH] [int] NOT NULL ,
[OF_HH] [int] NOT NULL ,
[OF_ZFZT] [bit] NOT NULL ,
[OF_GXSJ] [datetime] NOT NULL
) ON [PRIMARY]
--参数为字段值,返回该数据库中含有该值的所有表名及相应的字段名
select syscolumns.name as 字段名称,sysobjects.name as 所属表,
systypes.name 数据类型,syscolumns.length as 长度,syscolumns.prec as 精度,syscolumns.scale 小数位数,
isnullable as 允许空值,sysobjects.xtype as 类型
from syscolumns ,sysobjects , systypes
where syscolumns.id=sysobjects.id and sysobjects.status>=0
and systypes.xtype=syscolumns.xtype
and sysobjects.name in
(select sysobjects.name from syscolumns ,sysobjects
where syscolumns.id=sysobjects.id and syscolumns.name like '%HH%')
CREATE TABLE [dbo].[SPFP] (
[OF_DH] [int] NOT NULL ,
[OF_HH] [int] NOT NULL ,
[OF_ZFZT] [bit] NOT NULL ,
[OF_GXSJ] [datetime] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[SPPJ] (
[OF_DH] [int] NOT NULL ,
[OF_HH] [int] NOT NULL ,
[OF_ZFZT] [bit] NOT NULL ,
[OF_GXSJ] [datetime] NOT NULL
) ON [PRIMARY]
--参数为字段值,返回该数据库中含有该值的所有表名及相应的字段名
select syscolumns.name as 字段名称,sysobjects.name as 所属表,
systypes.name 数据类型,syscolumns.length as 长度,syscolumns.prec as 精度,syscolumns.scale 小数位数,
isnullable as 允许空值,sysobjects.xtype as 类型
from syscolumns ,sysobjects , systypes
where syscolumns.id=sysobjects.id and sysobjects.status>=0
and systypes.xtype=syscolumns.xtype
and sysobjects.name in
(select sysobjects.name from syscolumns ,sysobjects
where syscolumns.id=sysobjects.id and syscolumns.name like '%HH%')
#8
字段值放到最后一句的:'%HH%'中吗?可是这是查字段名,请再帮我看一下。
#9
先给zhunanhui 5分,谢谢
#1
不好写,你知道的信息太少了,写起来会很长,你看起来也会非常吃力,你要多多想想还知道什么信息可以提供的.
#2
研究下系统表,建议提供字段值外还提供数据类型,否则不同类型数据的比较将相当麻烦
#3
学习+++++++
#4
查系统表, 用动态SQL吧
#5
需求不足,难实现!
field的类型都没有规定.写起来麻烦
field的类型都没有规定.写起来麻烦
#6
如果字段类型为:varchar
#7
--建两个表来测试一下
CREATE TABLE [dbo].[SPFP] (
[OF_DH] [int] NOT NULL ,
[OF_HH] [int] NOT NULL ,
[OF_ZFZT] [bit] NOT NULL ,
[OF_GXSJ] [datetime] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[SPPJ] (
[OF_DH] [int] NOT NULL ,
[OF_HH] [int] NOT NULL ,
[OF_ZFZT] [bit] NOT NULL ,
[OF_GXSJ] [datetime] NOT NULL
) ON [PRIMARY]
--参数为字段值,返回该数据库中含有该值的所有表名及相应的字段名
select syscolumns.name as 字段名称,sysobjects.name as 所属表,
systypes.name 数据类型,syscolumns.length as 长度,syscolumns.prec as 精度,syscolumns.scale 小数位数,
isnullable as 允许空值,sysobjects.xtype as 类型
from syscolumns ,sysobjects , systypes
where syscolumns.id=sysobjects.id and sysobjects.status>=0
and systypes.xtype=syscolumns.xtype
and sysobjects.name in
(select sysobjects.name from syscolumns ,sysobjects
where syscolumns.id=sysobjects.id and syscolumns.name like '%HH%')
CREATE TABLE [dbo].[SPFP] (
[OF_DH] [int] NOT NULL ,
[OF_HH] [int] NOT NULL ,
[OF_ZFZT] [bit] NOT NULL ,
[OF_GXSJ] [datetime] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[SPPJ] (
[OF_DH] [int] NOT NULL ,
[OF_HH] [int] NOT NULL ,
[OF_ZFZT] [bit] NOT NULL ,
[OF_GXSJ] [datetime] NOT NULL
) ON [PRIMARY]
--参数为字段值,返回该数据库中含有该值的所有表名及相应的字段名
select syscolumns.name as 字段名称,sysobjects.name as 所属表,
systypes.name 数据类型,syscolumns.length as 长度,syscolumns.prec as 精度,syscolumns.scale 小数位数,
isnullable as 允许空值,sysobjects.xtype as 类型
from syscolumns ,sysobjects , systypes
where syscolumns.id=sysobjects.id and sysobjects.status>=0
and systypes.xtype=syscolumns.xtype
and sysobjects.name in
(select sysobjects.name from syscolumns ,sysobjects
where syscolumns.id=sysobjects.id and syscolumns.name like '%HH%')
#8
字段值放到最后一句的:'%HH%'中吗?可是这是查字段名,请再帮我看一下。
#9
先给zhunanhui 5分,谢谢