SqlServer2005 清空数据问题! 现在,有个规模比较大,数据量比较多的DB,因为某种原因,我需要清空全部数据。但要保留 整个数据库构成。有什么好的办法没有?表实在太多,挨个写DELETE不现实,而且还有很多外键关系!写程序删除,频繁出现数据库日志文件已满! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用truncate table tablename 这个没日志的 或在数据库中生成 SQL 角本后,删除 当前库后用SQL文件 重新建库 或者如happyflystone所言,删除表后,重新建立表. 用SQL脚本的办法,也不太可行。该数据库中含有 500多存储过程,200多触发器,以及300左右的用户自定义函数。这些我都有文本格式的存档,可是一个一个的执行也费劲死!555555 以下我是在微软事例数据库做的例子你利用这样的查询语句查询出所有的清楚表数据的语句然后执行以下 所有truncate table 就可以得到所有数据库结构了select 'truncate table '+name from sys.objects where type='u'order by name(70 行受影响)truncate table Addresstruncate table AddressTypetruncate table AWBuildVersiontruncate table BillOfMaterialstruncate table Contacttruncate table ContactCreditCardtruncate table ContactTypetruncate table CountryRegiontruncate table CountryRegionCurrencytruncate table CreditCardtruncate table Culturetruncate table Currencytruncate table CurrencyRatetruncate table Customertruncate table CustomerAddresstruncate table DatabaseLogtruncate table Departmenttruncate table Documenttruncate table Employeetruncate table EmployeeAddresstruncate table EmployeeDepartmentHistorytruncate table EmployeePayHistorytruncate table ErrorLogtruncate table Illustrationtruncate table Individualtruncate table JobCandidatetruncate table Locationtruncate table Producttruncate table ProductCategorytruncate table ProductCostHistorytruncate table ProductDescriptiontruncate table ProductDocumenttruncate table ProductInventorytruncate table ProductListPriceHistorytruncate table ProductModeltruncate table ProductModelIllustrationtruncate table ProductModelProductDescriptionCulturetruncate table ProductPhototruncate table ProductProductPhototruncate table ProductReviewtruncate table ProductSubcategorytruncate table ProductVendortruncate table PurchaseOrderDetailtruncate table PurchaseOrderHeadertruncate table SalesOrderDetailtruncate table SalesOrderHeadertruncate table SalesOrderHeaderSalesReasontruncate table SalesPersontruncate table SalesPersonQuotaHistorytruncate table SalesReasontruncate table SalesTaxRatetruncate table SalesTerritorytruncate table SalesTerritoryHistorytruncate table ScrapReasontruncate table Shifttruncate table ShipMethodtruncate table ShoppingCartItemtruncate table SpecialOffertruncate table SpecialOfferProducttruncate table StateProvincetruncate table Storetruncate table StoreContacttruncate table TransactionHistorytruncate table TransactionHistoryArchivetruncate table UnitMeasuretruncate table Vendortruncate table VendorAddresstruncate table VendorContacttruncate table WorkOrdertruncate table WorkOrderRouting @tablename用游标取出来exec('truncate table '+@tablename) 想批量操作,最好的办法就是用utpcb的方法。结合系统表,先SELECT出需要执行的语句,然后把结果COPY出来执行就可以了。 sp_msforeachtable "tracert table ?" !!!!!!!急问:VC6连接SQL2000/2005程序执行都正常,换成2008后,连接正常,但是一执行存储过程就报错!!!!! 表合并查询 求一SQL(在线等!) 关于MSDE的问题 双表联合查询,一次得到最后结果的SQL语句怎么写? 数据库字段问题 服务器能启动,但是建立连接时候出错,general network error, 关于日期格式 存储过程咋样解密 TTable组件如何实现自动LOGIN数据库? 能取到存储过程理的第二个数据集吗? ★数据库中,这个判断语句怎么写?在线等指教!!
这些我都有文本格式的存档,可是一个一个的执行也费劲死!555555
你利用这样的查询语句查询出所有的清楚表数据的语句然后执行以下 所有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
@tablename用游标取出来exec('truncate table '+@tablename)
结合系统表,先SELECT出需要执行的语句,然后把结果COPY出来执行就可以了。