﻿--同步重阅申请表结构后，再维护该字段

UPDATE VisitTaskReReading
SET TrialId = VisitTask.TrialId
FROM VisitTaskReReading 
INNER JOIN VisitTask ON VisitTaskReReading.OriginalReReadingTaskId = VisitTask.Id;

delete VisitTaskReReading where TrialId is NULL

-- 查询

  SELECT 
                                 TableName  = d.name,          --表名称
                              
                                 ColumnNumber   = a.colorder,  --列序号
                                 ColumnName     = a.name,      --列名称
								    IsNotCanNull     = case when a.isnullable=1 then 0 else 1 end,   --允许空
                                 Columntype       = b.name,          --类型
                                 ColumnLength       = COLUMNPROPERTY(a.id,a.name,'PRECISION')   --长度

                             	
                             FROM 
                                 syscolumns a
                             left join 
                                 systypes b 
                             on 
                                 a.xusertype=b.xusertype
                             inner join 
                                 sysobjects d 
                             on 
                                 a.id=d.id  and d.xtype in ('U') and  d.name<>'dtproperties'
                             left join 
                                 syscomments e 
                             on 
                                 a.cdefault=e.id
                             left join 
                             sys.extended_properties   g 
                             on 
                                 a.id=G.major_id and a.colid=g.minor_id  
                             left join
                             sys.extended_properties f
                             on 
                                 d.id=f.major_id and f.minor_id=0
                             where (b.name='nvarchar' or  b.name='varchar') and  COLUMNPROPERTY(a.id,a.name,'PRECISION') <100 and  COLUMNPROPERTY(a.id,a.name,'PRECISION') !=-1
                             order by 
                                 a.id,a.colorder