473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

truncate a table ignoring relations

chathura86
227 100+
hi,
i have a table which has child rows in another table. Now i want to truncate this
table temporally, because i will re-enter those values in a short time with some changes. cannot use update statement to make those changes. only possible way is truncating and inserting.

also i want to insert some data in to child rows without any parent rows. as in the previous section i can add the relevant parent rows shortly.

its like i want to ignore all the relations temporally while I’m performing this operation. After finishing it relations should work properly. it is 100% sure that the data is in the correct order to perform relations after i complete this operation.

Thank you,

Chathura Bamunusinghe
Oct 11 '07 #1
3 5436
amitpatel66
2,367 Expert 2GB
hi,
i have a table which has child rows in another table. Now i want to truncate this
table temporally, because i will re-enter those values in a short time with some changes. cannot use update statement to make those changes. only possible way is truncating and inserting.

also i want to insert some data in to child rows without any parent rows. as in the previous section i can add the relevant parent rows shortly.

its like i want to ignore all the relations temporally while I’m performing this operation. After finishing it relations should work properly. it is 100% sure that the data is in the correct order to perform relations after i complete this operation.

Thank you,

Chathura Bamunusinghe
In case of primary key - foreign key relationship, you can disable the primary key of the table with CASCADE options. The cascase option will disable the refrential integrity constraints also. After disabling the constraints, you can perfomr TRUNCATE or DELETE/INSERT operations. Then you can ENABLE the constraints again

For disabling and enabling a constraint:

Expand|Select|Wrap|Line Numbers
  1.  
  2. ALTER TABLE table_name DISABLE PRIMARY KEY CASCADE;
  3.  
  4. ALTER TABLE table_name ENABLE PRIMARY KEY;
  5.  
  6.  
Oct 11 '07 #2
chathura86
227 100+
In case of primary key - foreign key relationship, you can disable the primary key of the table with CASCADE options. The cascase option will disable the refrential integrity constraints also. After disabling the constraints, you can perfomr TRUNCATE or DELETE/INSERT operations. Then you can ENABLE the constraints again

For disabling and enabling a constraint:

Expand|Select|Wrap|Line Numbers
  1.  
  2. ALTER TABLE table_name DISABLE PRIMARY KEY CASCADE;
  3.  
  4. ALTER TABLE table_name ENABLE PRIMARY KEY;
  5.  
  6.  
it was a good solution,
thanks a lot.

chathura bamunusinghe
Oct 17 '07 #3
amitpatel66
2,367 Expert 2GB
it was a good solution,
thanks a lot.

chathura bamunusinghe
Hi,

You are Welcome!!
DO POST any issues in future, we will help you out!!

Regards,
Amit
Oct 17 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ed | last post by:
I am trying to get some information to compare and contrast the Truncate Table function and the Drop Table function. I know that using Truncate Table is faster and saves the structure of the table...
3
by: martin | last post by:
Hi, We have a heavily used production server and a table which logs every hit on a web site. This table has grown large over time and we want to clear it down as efficiently as possible. We would...
3
by: LineVoltageHalogen | last post by:
Greeting All, I have a stored proc that dynamically truncates all the tables in my databases. I use a cursor and some dynamic sql for this: ...... create cursor Loop through sysobjects and...
5
by: ronin 47th | last post by:
Hi group, In one of the books 'Gurus Guide to Transact SQL' i found this info: ------------------------------------------------------------ TRUNCATE TABLE empties a table without logging row...
2
by: rdraider | last post by:
Hi, I am trying to create a script that deletes transaction tables and leaves master data like customer, vendors, inventory items, etc. How can I use TRUNCATE TABLE with an Exists? My problem is...
2
by: Neil | last post by:
Can one use Truncate Table on a linked server table? When I try it, I get a message that only two prefixes are allowed. Here's what I'm using: Truncate Table svrname.dbname.dbo.tablename
14
by: Sala | last post by:
Hi I want to truncate all data in database ... pls help me how i ll truncate?
10
by: Troels Arvin | last post by:
Hello, Until this date, I believed that DB2 has no TRUNCATE TABLE command. But then I came across...
2
by: Boogha | last post by:
I have a cursor looping through a list of tables that I want to truncate and then do a bulk insert into, Is this possible in SQL Server 2000 or do script each table individually. Cheers, Adam
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.