SQL Server finds objects that contain strings

Source: Internet
Author: User

SQL Server finds objects that contain strings

SELECTSm.object_id,object_name(Sm.object_id) as object_name, O.type, O.type_desc, Sm.definition fromSys.sql_modules asSMJOINSys.objects asO onSm.object_id =O.object_idwhereSm.definition like '% of content to match%' --Collate SQL_Latin1_General_CP1_CI_ASORDER  byO.type;GOSelect object_name(ID) as object_name,text fromsyscommentswhere text  like '% of content to match%'--Declare The text we want to search forDECLARE @Text nvarchar(4000);SET @Text = 'What to match';--Get the schema name, table name, and table type for:--Table NamesSELECTTable_schema as 'Object Schema', table_name as 'Object Name', Table_type as 'Object Type'      ,'Table Name'   as 'TEXT Location' frominformation_schema. TABLESWHEREtable_name like '%'+@Text+'%'UNION --Column NamesSELECTTable_schema as 'Object Schema', column_name as 'Object Name'      ,'COLUMN'       as 'Object Type'      ,'Column Name'  as 'TEXT Location' frominformation_schema. COLUMNSWHEREcolumn_name like '%'+@Text+'%'UNION--Function or procedure bodiesSELECTSpecific_schema as 'Object Schema', Routine_name as 'Object Name', Routine_type as 'Object Type', Routine_definition as 'TEXT Location' frominformation_schema. ROUTINESWHERERoutine_definition like '%'+@Text+'%'       and(Routine_type= 'function' ORRoutine_type= 'procedure');

SQL Server finds objects that contain strings

Related Article

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.