Home Database Mysql Tutorial 查看数据库中的字段所在的表中或某值所在的表和字段

查看数据库中的字段所在的表中或某值所在的表和字段

Jun 07, 2016 pm 02:58 PM
Field database Check in the table

查看数据库中的字段所在的表中或某值所在的表和字段 ***********************************字段在哪个表中 select tab.name table_name, col.name column_name from sysobjects tab left join syscolumns col on tab.id = col.id and tab.xtype = U where col

查看数据库中的字段所在的表中或某值所在的表和字段

 

***********************************字段在哪个表中

select tab.name table_name, col.name column_name

  from sysobjects tab

  left join syscolumns col on tab.id = col.id and tab.xtype = 'U'

 where col.name like '%fkfz10000003%'  order by 1,2

 

*************************************查询整个数据库中某个特定值所在的表和字段的方法

 

通过做一个存储过程,只需要传入一个想要查找的值,即可查询出这个值所在的表和字段名。前提是要将这个存储过程放在所查询的数据库。

 

CREATE PROCEDURE [dbo].[SP_FindValueInDB]

(

    @value VARCHAR(1024)

)        

AS

BEGIN

    -- SET NOCOUNT ON added to prevent extra result sets from

    -- interfering with SELECT statements.

SET NOCOUNT ON;

DECLARE @sql VARCHAR(1024) 

DECLARE @table VARCHAR(64) 

DECLARE @column VARCHAR(64) 

 

CREATE TABLE #t ( 

    tablename VARCHAR(64), 

    columnname VARCHAR(64) 

 

DECLARE TABLES CURSOR 

FOR 

 

    SELECT o.name, c.name 

    FROM syscolumns c 

    INNER JOIN sysobjects o ON c.id = o.id 

    WHERE o.type = 'U' AND c.xtype IN (167, 175, 231, 239) 

    ORDER BY o.name, c.name 

 

OPEN TABLES 

 

FETCH NEXT FROM TABLES 

INTO @table, @column 

 

WHILE @@FETCH_STATUS = 0 

BEGIN 

    SET @sql = 'IF EXISTS(SELECT NULL FROM [' + @table + '] ' 

    SET @sql = @sql + 'WHERE RTRIM(LTRIM([' + @column + '])) LIKE ''%' + @value + '%'') ' 

    SET @sql = @sql + 'INSERT INTO #t VALUES (''' + @table + ''', ''' 

    SET @sql = @sql + @column + ''')' 

 

    EXEC(@sql) 

 

    FETCH NEXT FROM TABLES 

    INTO @table, @column 

END 

 

CLOSE TABLES 

DEALLOCATE TABLES 

 

SELECT * 

FROM #t 

 

DROP TABLE #t 

 

End

 

例如,要查询‘admin’,新建一个查询输入

 

EXEC SP_FindValueInDB 'admin'

会返回相应记录,Tablename显示被查询数据所在表,Columnname显示被查询数据所在

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to view the hot list of Kuaishou Live Companion videos How to view the hot list of Kuaishou Live Companion videos Mar 29, 2024 pm 08:09 PM

Kuaishou Live Companion is not only a powerful live broadcast auxiliary tool, but also a real-time insight platform for hot topics and trends created for broadcasters. Through this function, anchors can quickly capture the content that audiences are most concerned about, and then adjust the live content to make it more in line with the audience's tastes and interests. So how to check the hot video list in the Kuaishou Live Companion app? This tutorial guide will provide you with a detailed introduction to the steps. I hope it can help you. How to view the hot video list on Kuaishou Live Companion? The second step is to click on the daily video hot list. The third step is to check the daily video hot list.

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

How do I check which groups I have joined? How do I check which groups I have joined? Apr 01, 2024 pm 05:34 PM

WeChat group chat is not only a simple chat platform, but also a communication circle that brings together elites and enthusiastic friends from all walks of life. So today I will teach you how to see how many groups you have added on WeChat and how to save group chats. Usually Users who use WeChat must not miss it. How to check how many groups you have added to WeChat and how to save group chats To check how many groups you have added to WeChat: 1. You can view your group chat window in the WeChat main interface 2. If you have already saved the group chat, you can tap [ Address Book] - [Group Chat] 3. After entering the group chat, you can view the saved group. Save the WeChat group: 1. Select the group you want to save, top right [...] 2. Open in the chat message [Save to address book] 3. On the main WeChat interface, tap [Address Book]-[Group Chat] to view

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How to view the Amap Help Center_How to view the Amap Help Center How to view the Amap Help Center_How to view the Amap Help Center Apr 01, 2024 pm 05:26 PM

1. We first open the Gaode map. 2. Then click (My) in the lower right corner of the Amap homepage and then click Settings in the upper right corner. 3. Finally, you can see the help center of Amap.

An in-depth analysis of how HTML reads the database An in-depth analysis of how HTML reads the database Apr 09, 2024 pm 12:36 PM

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

See all articles