|
Sybase |
For Sybase, you must provide a RI map with tables listed in child to parent order. I don't look at the referential integrity names for Sybase. Sybase doesn't need them. But if you are a Sybase user, use psTruncateTables (not psGTruncateTables) to truncate tables. psTruncateTables automatically searches the system catalog for referential integrity constraints and automatically writes the script to truncate child tables first. psTruncateTables also truncates tables for a specified owner. At the time of this writing, Sybase is the only database that handles table truncation and foreign key constraints correctly. That is, if all the child tables are empty, Sybase will allow you to truncate the parent tables. Believe it or not, Oracle 8.1 and Microsoft SQL Server 7.0 will not let you do this. Oracle and Microsoft products are too stupid to go check if the child tables are empty. |
|
Oracle |
For Oracle, you must provide a RI map with outgoing referential integrity constraints with tables listed in child to parent order. I have provided 2 Oracle options. In Oracle 8.0, you can truncate parent tables when their child tables have no rows. In Oracle 8.1, you cannot. For 8.1, I have to disable the foreign key constraints of the child table, even if the child table is empty, before I go ahead and truncate the parent table. Yes, one should consider this a bug in Oracle. Oracle regards this as a feature. Writing Oracle scripts SQL*Plus with PL/SQL is a challenge. Oracle SQL is extremely deficient in features. What is easy to write in Sybase or Microsoft SQL Server is a nightmare in Oracle. One of the reasons why psGTruncateTables must generate a script which spools repetitively to a temporary file is because Oracle lacks the simple SQL language construct of a 'conditional DDL statement.' For example, 'if table exists, truncate table'. This is impossible with Oracle. Yes, one should deem this as a critical problem with Oracle. Given this this one gigantic deficiency, no one should buy Oracle. Oracle, however, thinks this is normal. The goal of the author of DBPowerSuite, is to generate scripts which run without error. No one wants to give scripts to their user communities which blow up. What makes Oracle really awful in this aspect, is that Oracle's programming technique is based on blowing up, and then afterwards, checking for errors. It is literally impossible to write Oracle SQL DDL scripts which don't blow up. I have done the best I can to generate scripts which will not blow under normal circumstances. However, by checking for table existence and then spooling a truncate table SQL statement which executes later, I open a hole in transactional integrity. There is no way around this in Oracle. Oracle, believe it or not, regards this as normal. |
|
Microsoft SQL Server |
For MS SQL Server, you must provide a RI map with incoming referential integrity constraints with tables listed in child to parent order. Microsoft SQL Server 7.0 is a lot like Oracle 8.1 in the sense that the database server cannot truncate a parent table even if the children are rowless. SQL Server 7.0 is worse than Oracle 8.1 because SQL Server provides no way to disable the referential integrity constraints. Therefore for SQL Server, I will truncate the child tables, but I delete from the parent tables. Watch out because the SQL delete command logs transactions. |
|
Other Databases and You Also Have Sybase |
If you use Sybase anywhere in your shop and you want to write truncate scripts for Oracle, Informix, ODBC or MS SQL Server, you can first run psGenerateRIMap -Or against your Sybase database in order to get the correct child/parent table order. If you don't have Sybase, you'll have to figure out the child/parent table order manually. |