导航:首页 > 数据分析 > 如何查询数据库关键字段

如何查询数据库关键字段

发布时间:2023-06-08 15:24:17

㈠ 如何查找数据库中某一字段值

1.查询数据库中的所有数据库名:
SELECT Name FROM Master..SysDatabases ORDER BY Name

2.查询某个数据库中所有的表名:
SELECT Name FROM SysObjects Where XType='U' ORDER BY Name

3.查询表结构信息:

1 SELECT (case when a.colorder=1 then d.name else null end) 表名,
2 a.colorder 字段序号,a.name 字段名,
3 (case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end) 标识,
4 (case when (SELECT count(*) FROM sysobjects
5 WHERE (name in (SELECT name FROM sysindexes
6 WHERE (id = a.id) AND (indid in
7 (SELECT indid FROM sysindexkeys
8 WHERE (id = a.id) AND (colid in
9 (SELECT colid FROM syscolumns WHERE (id = a.id) AND (name = a.name)))))))
10 AND (xtype = 'PK'))>0 then '√' else '' end) 主键,b.name 类型,a.length 占用字节数,
11 COLUMNPROPERTY(a.id,a.name,'PRECISION') as 长度,
12 isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as 小数位数,(case when a.isnullable=1 then '√'else '' end) 允许空,
13 isnull(e.text,'') 默认值,isnull(g.[value], ' ') AS [说明]
14 FROM syscolumns a
15 left join systypes b on a.xtype=b.xusertype
16 inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
17 left join syscomments e on a.cdefault=e.id
18 left join sys.extended_properties g on a.id=g.major_id AND a.colid=g.minor_id
19 left join sys.extended_properties f on d.id=f.class and f.minor_id=0
20 where b.name is not null
21 --WHERE d.name='要查询的表' --如果只查询指定表,加上此条件
22 order by a.id,a.colorder

㈡ 如何使用sql server查询整个数据库某一个关键字

感觉你最好先搞个查询,别直接替换,风险太大。

代码如下(这个是查找库里所有记录中含“张三”的数据,替换里边的张三那个字符串就行):

declare@cloumnsvarchar(40)
declare@tablenamevarchar(40)
declare@strvarchar(40)
declare@countsint
declare@sqlnvarchar(2000)
declareMyCursorCursorFor
Selecta.nameasColumns,b.,sysobjectsb,systypesc
wherea.id=b.id
andb.type='U'
anda.xtype=c.xtype
andc.namelike'%char%'
set@str='张三'
OpenMyCursor
FetchnextFromMyCursorInto@cloumns,@tablename
While(@@Fetch_Status=0)
Begin
set@sql='select@tmp_counts=count(*)from'+@tablename+'where'+@cloumns+'='''+@str+''''
executesp_executesql@sql,N'@tmp_countsintout',@countsout
if@counts>0
begin
print'表名为:'+@tablename+',字段名为'+@cloumns
end
FetchnextFromMyCursorInto@cloumns,@tablename
End
CloseMyCursor
DeallocateMyCursor

㈢ mysql数据库如何搜索关键词

办法如下:

select * from table1 where concat(`字段`,`字段`,`字段` ) like '%关键字%' union
select * from table2 where concat(`字段`,`字段`,`字段` ) like '%关键字%' union
select * from table3 where concat(`字段`,`字段`,`字段` ) like '%关键字%' union
select * from table4 where concat(`字段`,`字段`,`字段` ) like '%关键字%' union
select * from table5 where concat(`字段`,`字段`,`字段` ) like '%关键字%'
前提是查询出来的字段个数要一样,类型要对应好,至于如何得到正确且符合你需要的sql就要在程序类中处理了。

㈣ sql 数据库中所有表中查询关键字

用游标循环以下,可能效率有点低,以下是我写的一个存储过程语句供参考
--exec searchkeyword '物理'
Create proc searchkeyword(@keyword varchar(100))
as
begin
declare @tablename varchar(100),@colname varchar(100),@sql nvarchar(2000),@cou int
create table #t
(
tablename varchar(100),
colname varchar(100)
)
declare c1 cursor for
select a.name as TableName,b.name as ColName From sysobjects a
inner join syscolumns b on (a.id=b.id)
where a.xtype='U'
open c1
fetch next from c1 into @tablename,@colname
WHILE @@_STATUS = 0
begin
set @sql='select @count=count(*) from '+@tablename+' where '+@colname+'=@keyword'
begin try
exec sp_executesql @sql, N'@count int out,@keyword varchar(20)', @cou out ,@keyword
end try
begin catch
set @cou=0
end catch
if @cou>0
begin
insert into #t values(@tablename,@colname)
end
fetch next from c1 into @tablename,@colname
end
CLOSE c1
DEALLOCATE c1
select * from #t
end

㈤ 如何查询输出数据库中包含某字段关键词的全部条目

1.查询数据库中的所有数据库名:
SELECT Name FROM Master..SysDatabases ORDER BY Name

2.查询某个数据库中所有的表名:
SELECT Name FROM SysObjects Where XType='U' ORDER BY Name

3.查询表结构信息:

1 SELECT (case when a.colorder=1 then d.name else null end) 表名,
2 a.colorder 字段序号,a.name 字段名,
3 (case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end) 标识,
4 (case when (SELECT count(*) FROM sysobjects
5 WHERE (name in (SELECT name FROM sysindexes
6 WHERE (id = a.id) AND (indid in
7 (SELECT indid FROM sysindexkeys
8 WHERE (id = a.id) AND (colid in
9 (SELECT colid FROM syscolumns WHERE (id = a.id) AND (name = a.name)))))))
10 AND (xtype = 'PK'))>0 then '√' else '' end) 主键,b.name 类型,a.length 占用字节数,
11 COLUMNPROPERTY(a.id,a.name,'PRECISION') as 长度,
12 isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as 小数位数,(case when a.isnullable=1 then '√'else '' end) 允许空,
13 isnull(e.text,'') 默认值,isnull(g.[value], ' ') AS [说明]
14 FROM syscolumns a
15 left join systypes b on a.xtype=b.xusertype
16 inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
17 left join syscomments e on a.cdefault=e.id
18 left join sys.extended_properties g on a.id=g.major_id AND a.colid=g.minor_id
19 left join sys.extended_properties f on d.id=f.class and f.minor_id=0
20 where b.name is not null
21 --WHERE d.name='要查询的表' --如果只查询指定表,加上此条件
22 order by a.id,a.colorder

阅读全文

与如何查询数据库关键字段相关的资料

热点内容
列表文件存储路径 浏览:540
qq游戏大厅自动出语音 浏览:598
编程只是兴趣怎么办 浏览:223
荣耀6plus电信版本 浏览:584
能打开word文件但桌面上找不到 浏览:366
2020十大网络红歌有哪些 浏览:843
手机系统空间文件夹在哪里设置快捷键 浏览:309
通信网络中的b8什么意思 浏览:715
桌面文件标题 浏览:228
优淘集市有什么app 浏览:747
找不到收藏文件 浏览:711
战狼2在什么网站 浏览:785
vb修改word 浏览:650
c盘分页文件 浏览:277
ipad如何互相传输数据 浏览:567
我的世界如何用积木编程大师复制方块 浏览:638
进网站请求路径未找到是怎么回事 浏览:807
spss21教程 浏览:655
css商业网站布局之道pdf 浏览:892
c盘不能新建文件夹win10 浏览:384

友情链接