从sysobject表中读出所有用户表,然后对每一个表写增加字段的sql,最好用存储过程加游标来写。

解决方案 »

  1.   

    exec master..sp_msforeachtable 
    @command1='alter table ? add hit int',
    @whereand=' and name like ''N%'' '
      

  2.   

    这样就保险了:
    exec master..sp_msforeachtable 
    @command1='alter table ? add hit int',
    @whereand=' and name like ''N%'' and isnumberic(right(name,len(name)-1))=1 '
      

  3.   

    上面错了.
    isnumberic-->isnumeric
      

  4.   

    select 
    'ALTER TABLE dbo.'+NAME+'  ADD hit varchar(100)  NULL ' AS  hit,
    'exec sp_addextendedproperty N''MS_Description'', N''字符串'', N''user'', N''dbo'', N''table'', N'''+name+''', N''column'', N''hit'''
     from dbo.sysobjects where xtype='U'