/*
create by zhanglei
20061029
exec sp_searchtable '','','自增字段'
alter procedure sp_searchtable
@tablename varchar(125),
@colname varchar(120),
@subinfo varchar(200)
asset nocount on
--建立儲存結果資訊的**
if exists(select 1 from sysobjects where id = object_id(n'srchtbl'))
drop table srchtbl
create table srchtbl(ftbl varchar(120), fcol varchar(120), finfo varchar(200))
declare @ftablename varchar(120)
declare tablecursor cursor for
select name from sysobjects
where xtype ='u' and (charindex(@tablename,name) >0 or isnull(@tablename,'') = '')
open tablecursor
fetch next from tablecursor into @ftablename
while @@fetch_status =0
begin
declare @srchstr varchar(8000)
set @srchstr = ' select 1 from '+ @ftablename+ ' where (1=0) '
select @srchstr = @srchstr + ' or charindex(''' + @subinfo+''','+c.name+') >0 '
from syscolumns c
left join systypes t on c.xusertype = t.xusertype
where c.id = object_id(@ftablename) and t.name <> n'image'
and (charindex(@colname,c.name) >0 or isnull(@tablename,'') = '')
--執行動態sql語句,查詢結果
exec(@srchstr)
if @@rowcount > 0
begin
insert into srchtbl(ftbl,finfo) values(@ftablename,@subinfo)
end
--查詢下乙個表
fetch next from tablecursor into @ftablename
endclose tablecursor
deallocate tablecursor
--顯示結果
select * from srchtbl
set nocount off
根據字段值查詢其所在的表 字段
假如字段值 123456,根據其查詢表名和欄位名 declare what varchar 800 set what 123456 要搜尋的字串 declare sql varchar 8000 declare tablecursor cursor local for select sql if e...
mybatis plus查詢指定字段
mybatis plus select查詢語句預設是查全部字段,有兩種方法可以指定要查詢的字段 create table user id bigint 20 not null comment 主鍵 name varchar 30 default null comment 姓名 age int 11 ...
mysql查詢按照指定欄位的指定順序進行排序
之前我們已經了解的mysql按照中文進行排序的實現方法了 那麼如何按照指定欄位的指定順序進行排序呢?例如有乙個使用者表user,有id,username,status欄位,status的字段值有1,2,3,4四種情況,如何將使用者表中的資料按照status欄位的2,4,1,3順序進行排序呢?這時候需...