Empty database error: Because the table is referencing the workaround by the FOREIGN KEY constraint

Source: Internet
Author: User
Tags rtrim

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.