Brute Force search data

Source: Internet
Author: User

DECLARE @guid NVARCHAR(MAX)SET @guid = 'cf789c0e-b844-e511-8100-00155d0a6f04'DECLARE @index INT ,    @count INTSELECT  IDENTITY(INT,1,1) asID, Objects.name asTableName, Columns.name asColumnName,CONVERT(INT,NULL) asExistsdata into#columns fromsys.columns Left JOINSys.objects onObjects.object_id =Columns.object_idWHEREsystem_type_id=  $         andType= 'U'--and objects.name like ' y_% 'ORDER  byObjects.nameSELECT  @index = 1 ,        @count = @ @ROWCOUNT while @index <= @count    BEGIN        DECLARE @sql NVARCHAR(MAX)        SELECT  @sql = 'if exists (select 1 from' +TableName+ 'where'                +ColumnName+ ' = " " + @guid + " "begin Update #columns Set existsdata = 1 WHERE id ='                + CONVERT(NVARCHAR(MAX),@index)+ 'End'         from#columnsWHEREId= @index    --EXEC @sql        EXEC(@sql)        SET @index = @index + 1    ENDSELECT  * from#columnsWHEREExistsdata= 1DROP TABLE#columns

DECLARE @guid NVARCHAR (MAX) SET @guid = ' cf789c0e-b844-e511-8100-00155d0a6f04 '
DECLARE @index int, @count int
SELECT IDENTITY (int,1,1) as ID, objects.name as tablename, columns.name as ColumnName, CONVERT ( INT, NULL) as Existsdatainto #columnsFROM Sys.columns left JOIN sys.objects on objects.object_id = Columns.ob Ject_idwhere system_type_id = $ and type = ' U '--and objects.name like ' y_% ' ORDER by Objects.name
SELECT @index = 1, @count = @ @ROWCOUNTWHILE @index <= @count BEGIN DECLARE @sql NVARCHAR (MAX) Select @sql = ' If exists (select 1 from ' + tablename + ' where ' + ColumnName + ' = ' + ' + @guid + ') beg Inupdate #columns Set existsdata = 1 WHERE id = ' + CONVERT ' (NVARCHAR (MAX), @index) + ' End ' from # Columns WHERE id = @index--exec @sql EXEC (@sql) SET @index = @index + 1 END
SELECT *from #columnsWHERE existsdata = 1
DROP TABLE #columns

Brute Force search data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.