Today, a netizen asked me, he knows the field name, but want to know which tables have these fields, so that he convenient work, think about, wrote a stored procedure for him, I think there may be a netizen encountered this situation, so put it out for everyone reference.
1 Create procUsp_colum_search2 @column_name varchar( -)--Field name3 4 as5 /*6 LCL7 Date: 2015-07-148 call: Exec usp_colum_search ' KSDM '9 Description: Queries which tables have the columnTen */ One A - --declaring Cursors - DeclareSearch_curcursor for SelectId fromsyscolumnswhereName=@column_name the --declaring Variables - Declare @id int - - --Open Cursor + OpenSearch_cur - + --Start Moving A FetchSearch_cur into @id at --Start Loop - while(@ @FETCH_STATUS=0) - begin - Select object_name(@id) asTable name - FetchSearch_cur into @id - End in - --Close Cursors to CloseSearch_cur + deallocateSearch_cur
Query which table has a field