• 自动构造删除数据库在所有约束的语句


    --在建立Starter_Kits的reports数据库时,可能是因为多国语言的原回,Reports_LoadData.sql并不能加载数据,要先替换所有 ?,换成'号,并用以下语句删除所有约束,这样才能加载,我想微软件应有临时禁用约束的,但没找到,有找到的朋友可以提示我一下,在这谢了.
    --动态生成清除约束的语句
    create table fktab
    (
    PKTABLE_QUALIFIER sysname,
    PKTABLE_OWNER sysname,
    PKTABLE_NAME sysname,
    PKCOLUMN_NAME sysname,
    FKTABLE_QUALIFIER sysname,
    FKTABLE_OWNER sysname,
    FKTABLE_NAME sysname,
    FKCOLUMN_NAME sysname,
    KEY_SEQ int,
    UPDATE_RULE int,
    DELETE_RULE int,
    FK_NAME sysname,
    PK_NAME sysname,
    DEFERRABILITY int
    )

    delete fktab
    --生成约束信息
    select 'insert fktab exec sp_fkeys',[name] from sysobjects where xtype='U'
    select 'alter table ','['+[FKTABLE_NAME]+']','drop constraint ',fk_name from fktab

    --删除约束的所有语句
    insert fktab exec sp_fkeys Reports_EmployeeTerritories
    insert fktab exec sp_fkeys [Reports_Order Details]
    insert fktab exec sp_fkeys fktab
    insert fktab exec sp_fkeys Reports_Categories
    insert fktab exec sp_fkeys Reports_CustomerDemographics
    insert fktab exec sp_fkeys Reports_Customers
    insert fktab exec sp_fkeys Reports_Employees
    insert fktab exec sp_fkeys Reports_Region
    insert fktab exec sp_fkeys Reports_Shippers
    insert fktab exec sp_fkeys Reports_Suppliers
    insert fktab exec sp_fkeys Reports_CustomerCustomerDemo
    insert fktab exec sp_fkeys Reports_Orders
    insert fktab exec sp_fkeys Reports_Products
    insert fktab exec sp_fkeys Reports_Territories


    alter table [Reports_Products] drop    constraint  FK_Reports_Products_Categories
    alter table [Reports_CustomerCustomerDemo] drop   constraint  FK_CustomerCustomerDemo
    alter table [Reports_CustomerCustomerDemo] drop   constraint  FK_CustomerCustomerDemo_Customers
    alter table [Reports_Orders] drop   constraint  FK_Reports_Orders_Customers
    alter table [Reports_Employees] drop   constraint  FK_Employees_Employees
    alter table [Reports_EmployeeTerritories] drop   constraint  FK_EmployeeTerritories_Employees
    alter table [Reports_Orders] drop   constraint  FK_Orders_Employees
    alter table [Reports_Territories] drop   constraint  FK_Territories_Region
    alter table [Reports_Orders] drop   constraint  FK_Orders_Shippers
    alter table [Reports_Products] drop   constraint  FK_Products_Suppliers
    alter table [Reports_Order Details] drop   constraint  FK_Order_Details_Orders
    alter table [Reports_Order Details] drop   constraint  FK_Order_Details_Products
    alter table [Reports_EmployeeTerritories] drop   constraint  FK_EmployeeTerritories_Territories

  • 相关阅读:
    用mysql+redis实现微博feed架构上需要注意哪些问题
    windows7下安装zend studio5.5
    鼠标移出DIV层时,触发onMouseOut事件
    关于MVVM和RAC的一些拓展阅读
    Swift(上) 常量, 变量, 数据类型, 循环, 选择结构 简单函数
    SDWebImage的使用
    App Store新应用提审攻略
    关于iOS的推送服务的点点
    iOS开发代码规范
    伟大的RAC和MVVM入门(二)
  • 原文地址:https://www.cnblogs.com/hhq80/p/616384.html
Copyright © 2020-2023  润新知