If exists (select * From DBO. sysobjects where id = object_id (n' [DBO]. [p_search] ') and objectproperty (ID, n' isprocedure') = 1)
Drop procedure [DBO]. [p_search]
Go
/* -- Search for a string in the field of the table
/* -- Call example
Use pubs
Exec p_search n 'search characters'
--*/
Create proc p_search
@ STR nvarchar (1000) -- string to be searched
As
If @ STR = ''return
Declare @ s nvarchar (4000)
Create Table # T (Table Name: sysname; field name: sysname)
Declare TB cursor local
Select S = 'if exists (select 1 from ['+ Replace (B. name, ']', ']') + '] Where [' +. name + '] Like n'' %' + @ STR + '% '')
Print ''table and field: ['+ B. Name +']. ['+ A. Name +'] '''
From syscolumns a join sysobjects B on A. ID = B. ID
Where B. xtype = 'U' and A. Status> = 0
And a. xtype in (175,239, 231,167)
Open TB
Fetch next from TB into @ s
While @ fetch_status = 0
Begin
Exec (@ s)
Fetch next from TB into @ s
End
Close TB
Deallocate TB
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