现在,有个规模比较大,数据量比较多的DB,
因为某种原因,我需要清空全部数据。
但要保留 整个数据库构成。
有什么好的办法没有?表实在太多,挨个写DELETE不现实,而且还有很多外键关系!
写程序删除,频繁出现数据库日志文件已满!

解决方案 »

  1.   

    用truncate table tablename 这个没日志的
      

  2.   

    或在数据库中生成 SQL 角本后,删除 当前库后用SQL文件 重新建库
      

  3.   

    或者如happyflystone所言,删除表后,重新建立表.
      

  4.   

    用SQL脚本的办法,也不太可行。该数据库中含有 500多存储过程,200多触发器,以及300左右的用户自定义函数。
    这些我都有文本格式的存档,可是一个一个的执行也费劲死!555555
      

  5.   

    以下我是在微软事例数据库做的例子
    你利用这样的查询语句查询出所有的清楚表数据的语句然后执行以下 所有truncate  table  就可以得到所有数据库结构了
    select 'truncate  table '+name from sys.objects  where type='u'order by name
    (70 行受影响)
    truncate  table Address
    truncate  table AddressType
    truncate  table AWBuildVersion
    truncate  table BillOfMaterials
    truncate  table Contact
    truncate  table ContactCreditCard
    truncate  table ContactType
    truncate  table CountryRegion
    truncate  table CountryRegionCurrency
    truncate  table CreditCard
    truncate  table Culture
    truncate  table Currency
    truncate  table CurrencyRate
    truncate  table Customer
    truncate  table CustomerAddress
    truncate  table DatabaseLog
    truncate  table Department
    truncate  table Document
    truncate  table Employee
    truncate  table EmployeeAddress
    truncate  table EmployeeDepartmentHistory
    truncate  table EmployeePayHistory
    truncate  table ErrorLog
    truncate  table Illustration
    truncate  table Individual
    truncate  table JobCandidate
    truncate  table Location
    truncate  table Product
    truncate  table ProductCategory
    truncate  table ProductCostHistory
    truncate  table ProductDescription
    truncate  table ProductDocument
    truncate  table ProductInventory
    truncate  table ProductListPriceHistory
    truncate  table ProductModel
    truncate  table ProductModelIllustration
    truncate  table ProductModelProductDescriptionCulture
    truncate  table ProductPhoto
    truncate  table ProductProductPhoto
    truncate  table ProductReview
    truncate  table ProductSubcategory
    truncate  table ProductVendor
    truncate  table PurchaseOrderDetail
    truncate  table PurchaseOrderHeader
    truncate  table SalesOrderDetail
    truncate  table SalesOrderHeader
    truncate  table SalesOrderHeaderSalesReason
    truncate  table SalesPerson
    truncate  table SalesPersonQuotaHistory
    truncate  table SalesReason
    truncate  table SalesTaxRate
    truncate  table SalesTerritory
    truncate  table SalesTerritoryHistory
    truncate  table ScrapReason
    truncate  table Shift
    truncate  table ShipMethod
    truncate  table ShoppingCartItem
    truncate  table SpecialOffer
    truncate  table SpecialOfferProduct
    truncate  table StateProvince
    truncate  table Store
    truncate  table StoreContact
    truncate  table TransactionHistory
    truncate  table TransactionHistoryArchive
    truncate  table UnitMeasure
    truncate  table Vendor
    truncate  table VendorAddress
    truncate  table VendorContact
    truncate  table WorkOrder
    truncate  table WorkOrderRouting
      

  6.   


    @tablename用游标取出来exec('truncate table '+@tablename)
      

  7.   

    想批量操作,最好的办法就是用utpcb的方法。
    结合系统表,先SELECT出需要执行的语句,然后把结果COPY出来执行就可以了。
      

  8.   

    sp_msforeachtable "tracert table ?"