• SQL2000的系统表sysproperties在SQL2005中 无效的 问题


    有两种解决办法

    方法一、是我在网上找的:将原来的sysproperties改成sys.extended_properties并且对应关系如下

    sys.extended_properties
    left join sys.extended_properties g on a.id=g.class and

    a.colid=g.minor_id

    left join sys.extended_properties f on d.id=f.class and f.minor_id=0

    2000的数据库附加不能05的数据库里出了sysproperties不存在

    上面就是解决的方法,以后备用。

      【sysproperties】表 原来【SQL2000】中的表【sysproperties】在【SQL2005】中已经不存在了,被是表【extended_properties】取代了。  能不出错吗?

    微软公司在升级数据库版本的问题,怎么没有考虑到程序员?

    微软删除一个sysproperties表,不知道多少个基于【sysproperties】的程序要出问题。 

     

    所以基于上面的解决办法,我找到了

     第二个方法,相对比较简单

    建一个视图:

    CREATE VIEW sysproperties
    AS
     SELECT class AS id,Minor_id AS sMallid,* from sys.extended_properties

    这样以前写的代码 在找不到表的情况下就会用这个视图。

    暂时貌似可以解决问题

    举一个列子如下:修改后一样可以在2005中运行:

     --查询所有用户表所有字段的特征
    SELECT D.Name as TableName, A.colorder AS ColOrder, A.name AS Name,  
      COLUMNPROPERTY(A.ID,A.Name, 'IsIdentity') AS IsIdentity,  
      CASE WHEN EXISTS
      (SELECT 1
      FROM dbo.sysobjects
      WHERE Xtype = 'PK' AND Name IN
      (SELECT Name
      FROM sysindexes
      WHERE indid IN
      (SELECT indid
      FROM sysindexkeys
      WHERE ID = A.ID AND colid = A.colid)))  
      THEN 1 ELSE 0 END AS 主键,  
      B.name AS 类型,
      A.length AS [长度],
      A.xprec AS [精度],
      A.xscale AS [小数],
      CASE WHEN A.isnullable = 1 THEN 1 ELSE 0 END AS [可为空],  
    ISNULL(E.text, ' ') AS [默认值],  
      ISNULL(G.[value], ' ') AS [说明]
    FROM dbo.syscolumns A LEFT OUTER JOIN
      dbo.systypes B ON A.xtype = B.xusertype INNER JOIN
      dbo.sysobjects D ON A.id = D.id AND D.xtype = 'U' AND  
      D.name <> 'dtproperties' LEFT OUTER JOIN
      dbo.syscomments E ON A.cdefault = E.id 
      LEFT OUTER JOIN dbo.sysproperties G ON A.id = G.id AND A.colid = G.smallid
    --WHERE D.Name='tablename' --如果找指定表,把注释去掉
    ORDER BY 1, 2

    上面是 在2000中运行的效果,正确,没问题

    下面是利用【sys.extended_properties】的效果,用网上找的方法,可行

    --查询所有用户表所有字段的特征
    SELECT D.Name as TableName, A.colorder AS ColOrder, A.name AS Name,  
      COLUMNPROPERTY(A.ID,A.Name, 'IsIdentity') AS IsIdentity,  
      CASE WHEN EXISTS
      (SELECT 1
      FROM dbo.sysobjects
      WHERE Xtype = 'PK' AND Name IN
      (SELECT Name
      FROM sysindexes
      WHERE indid IN
      (SELECT indid
      FROM sysindexkeys
      WHERE ID = A.ID AND colid = A.colid)))  
      THEN 1 ELSE 0 END AS 主键,  
      B.name AS 类型,
      A.length AS [长度],
      A.xprec AS [精度],
      A.xscale AS [小数],
      CASE WHEN A.isnullable = 1 THEN 1 ELSE 0 END AS [可为空],  
    ISNULL(E.text, ' ') AS [默认值],  
      ISNULL(G.[value], ' ') AS [说明]
    FROM dbo.syscolumns A LEFT OUTER JOIN
      dbo.systypes B ON A.xtype = B.xusertype INNER JOIN
      dbo.sysobjects D ON A.id = D.id AND D.xtype = 'U' AND  
      D.name <> 'dtproperties' LEFT OUTER JOIN
      dbo.syscomments E ON A.cdefault = E.id 
    left join sys.extended_properties g 
    on a.id=g.class and 
    a.colid=g.minor_id
    left join sys.extended_properties f on d.id=f.class and f.minor_id=0
    WHERE D.Name='tablename' --如果找指定表,把注释去掉
    ORDER BY 1, 2

     

    另外我在 sql2005中建立视图 :

    CREATE VIEW sysproperties
    AS
     SELECT class AS id,Minor_id AS sMallid,* from sys.extended_properties

    后再执行第一个不经过修改用【sysproperties】的代码也能正常运行。

  • 相关阅读:
    Java基础之多线程没那么复杂!
    高性能Java RPC框架Dubbo与zookeeper的使用
    Java 学习之集合类(Collections)
    Java中List与数组互相转化
    AOJ-542-Window/POJ-2823-Window
    HDU-1074-Doing Homework
    HDU-5365-Run
    HDU-5366-The mook jong
    HDU-5391-Zball in Tina Town
    AOJ-351-求最值之差
  • 原文地址:https://www.cnblogs.com/kevinGao/p/3589954.html
Copyright © 2020-2023  润新知