SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


truncate table


truncate table

Author
Message
rajaster
rajaster
SSC Veteran
SSC Veteran (230 reputation)SSC Veteran (230 reputation)SSC Veteran (230 reputation)SSC Veteran (230 reputation)SSC Veteran (230 reputation)SSC Veteran (230 reputation)SSC Veteran (230 reputation)SSC Veteran (230 reputation)

Group: General Forum Members
Points: 230 Visits: 351
to the reply from igor to my post earlier. I didnt say delete the table. I was talking about removing the referenced data e.g

Table A
TableAID int PRIMARY Key IDENTITY(1,1),
data varchar(100)

Table B
TableBID INT PRIMARY Key,
TableAID INT FOREIGN KEY CONSTRAINT,
TableCID INT FOREIGN KEY CONSTRAINT

Table C
TableCID int PRIMARY Key IDENTITY(1,1),
Data Varchar(100)

In the past I've removed linked data that is referenced within TableB and removed them from TableB using deletes before then removing them from TableA or in my case there was more than one place with referenced foreign key data removing it before deleting from the main table did the job. especially as I was using Ids using Identity e.g ID = 1, and referencing Table B using this as a foreignKey.

I was expecting kapils example to be the same as above or similar in which case my advise was to also remove data from any table referencing data as best practice.

of course if data is not being referenced then fine go ahead use the delete and remove data from TableA. I've never had to remove constraints, seems pointless then having to recreate them.

If I misunderstood no worries. Looks like kapils resolved.
Igor Micev
Igor Micev
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10394 Visits: 5157
beebkhan (10/18/2012)
to the reply from igor to my post earlier. I didnt say delete the table. I was talking about removing the referenced data e.g

Table A
TableAID int PRIMARY Key IDENTITY(1,1),
data varchar(100)

Table B
TableBID INT PRIMARY Key,
TableAID INT FOREIGN KEY CONSTRAINT,
TableCID INT FOREIGN KEY CONSTRAINT

Table C
TableCID int PRIMARY Key IDENTITY(1,1),
Data Varchar(100)

In the past I've removed linked data that is referenced within TableB and removed them from TableB using deletes before then removing them from TableA or in my case there was more than one place with referenced foreign key data removing it before deleting from the main table did the job. especially as I was using Ids using Identity e.g ID = 1, and referencing Table B using this as a foreignKey.

I was expecting kapils example to be the same as above or similar in which case my advise was to also remove data from any table referencing data as best practice.

of course if data is not being referenced then fine go ahead use the delete and remove data from TableA. I've never had to remove constraints, seems pointless then having to recreate them.

If I misunderstood no worries. Looks like kapils resolved.



Hi,
Nice to reply.
I thought even not to remove the data as well as not to delete the table. You can retain the data with a default or nullable key for the FK using the ON DELETE adds to the FK definition.
Thanks
IgorMi

Igor Micev,
My blog: www.igormicev.com
GilaMonster
GilaMonster
SSC Guru
SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)

Group: General Forum Members
Points: 226851 Visits: 46335
kapil_kk (10/18/2012)
I think after disabling constraint of both tables truncate should work..


No, it shouldn't. Disabled constraint is still a constraint. For a truncate the table must not be referenced by a foreign key constraint at all.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


kapil_kk
kapil_kk
SSCertifiable
SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)

Group: General Forum Members
Points: 5366 Visits: 2767
thanks for the info Gila

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
kapil_kk
kapil_kk
SSCertifiable
SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)

Group: General Forum Members
Points: 5366 Visits: 2767
thanks beeb...
I am able to migrate the data after deleting data through delete statement rather than using Truncate statement

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search