查询表、字段信息-成都快上网建站

查询表、字段信息

-----------------------------------------------------------------------------------------------------------------------------------------------------
use DSCSYS
go
DECLARE 
     @TableName nvarchar(100) = 'COPTD'        
    ,@DataBase nvarchar(100) = 'TOPLED2015' 
    ,@SQL nvarchar(4000)    
    ,@Where nvarchar(4000) = ' where '
set @SQL = 'select MD001,MD003,MD004,MD005,MD006,MD007 from DSCSYS..ADMMD where MD001 = '+ '''' + 
            @TableName +  ''' and substring(MD003,1,2)  =  substring(''' + @TableName + ''',4,2)'
exec(@SQL)

----------------------------------------------------------------------------------------------------------------------------------------------------
set @SQL =  
    STUFF((SELECT ','+ rtrim(MD003) + ' as ''' +  rtrim(MD004) + ''''
            FROM ADMMD 
            where MD001 = @TableName and substring(MD003,1,2) = substring(@TableName,4,2)
            FOR xml path('')),1,1,'')  
set @SQL =replace('select * from ','*',@SQL) + @DataBase + '..' + @TableName    
exec(@SQL)      
-------------------------------------------------------------------------------------------------------------------------------------------------------
select MD001,MD003,MD004,MD005,MD006,MD007,* from DSCSYS..ADMMD 
where MD001 = 'PURTC' and MD003 = 'UDF12'
update DSCSYS..ADMMD  set UDF01 = '质保年限'
where MD001 = 'PURTC' and MD003 = 'UDF12'

网页标题:查询表、字段信息
分享路径:http://kswjz.com/article/jdsesg.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流