Five questions were resolved as follows
1. Clear the data
2. There is a foreign key can also, because it is reversed, deleted from the last table. And you are using delete because TRUNCATE cannot have a table with a foreign key
3. Seed issue, if the table has a seed reset to 0, do not operate if it does not exist
4. Add a business, an error in the middle, a chance to regret
5. Truncate log function, because using delete, the log file will increase after deletion, can not use
if(object_id('Pr_dataclear') is not NULL ) Drop procedurePr_dataclearGo Create procedurePr_dataclear as begin Transaction Declare @cTblName varchar( -) DeclareCur_clearcursor for Select RTrim(name) fromsysobjectswhereType= 'U' Order byCrdatedesc OpenCur_clearDeclare @cSQL varchar(255) Fetch Next fromCur_clear into @cTblName while(@ @fetch_status = 0) begin Set @cSQL = 'Delete from' + @cTblName Print @cSQL exec(@cSQL ) if(Ident_seed(@cTblName) is not NULL ) begin DBCCCheckident (@cTblName, Reseed,0 ) Print 'with seed and successfully reset to 1' End Fetch Next fromCur_clear into @cTblName End CloseCur_cleardeallocateCur_clearCommit Go --Clear all table dataexecPr_dataclear--Truncate logBackup LogLZ's Database withno_logDBCCshrinkdatabase (LZ's database)DBCCupdateusage (LZ's database)--View table Space (approximate)Select object_name(ID) asTable Name, (RTrim(8*Reserved/1024x768)+ 'MB') asTotal, (RTrim(8*Dpages/1024x768)+ 'MB') ashas been used, (RTrim(8*(Reserved-Dpages)/1024x768)+ 'MB') asNot used, (RTrim(8*Dpages/1024x768-Rows/1024x768*Minlen/1024x768)+ 'MB') asvoid fromsysindexeswhereIndid=1 Order byReserveddesc
Source: http://topic.csdn.net/u/20090816/17/EE0FA21E-8616-4236-A9CB-8C5A3D45C9D9.html 45 Floor
Empty database error: Because the table is referencing the workaround by the FOREIGN KEY constraint