Truncating all tables in a Postgres database

I regularly need to delete all the data from my PostgreSQL database before a rebuild. How would I do this directly in SQL? At the moment I’ve managed to come up with a SQL statement that returns all the commands I need to execute: SELECT ‘TRUNCATE TABLE ‘ || tablename || ‘;’ FROM pg_tables WHERE … Read more

Truncating long strings with CSS: feasible yet?

Is there any good way of truncating text with plain HTML and CSS, so that dynamic content can fit in a fixed-width-and-height layout? I’ve been truncating server-side by logical width (i.e. a blindly-guessed number of characters), but since a ‘w’ is wider than an ‘i’ this tends to be suboptimal, and also requires me to … Read more

What’s the difference between TRUNCATE and DELETE in SQL

What’s the difference between TRUNCATE and DELETE in SQL? If your answer is platform specific, please indicate that. 32 Answers 32 Here’s a list of differences. I’ve highlighted Oracle-specific features, and hopefully the community can add in other vendors’ specific difference also. Differences that are common to most vendors can go directly below the headings, … Read more

Cannot truncate table because it is being referenced by a FOREIGN KEY constraint?

Using MSSQL2005, can I truncate a table with a foreign key constraint if I first truncate the child table (the table with the primary key of the FK relationship)? I know that I can either Use a DELETE without a where clause and then RESEED the identity (or) Remove the FK, truncate the table, and … Read more

How to truncate a foreign key constrained table?

Why doesn’t a TRUNCATE on mygroup work? Even though I have ON DELETE CASCADE SET I get: ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (mytest.instance, CONSTRAINT instance_ibfk_1 FOREIGN KEY (GroupID) REFERENCES mytest.mygroup (ID)) drop database mytest; create database mytest; use mytest; CREATE TABLE mygroup ( ID INT NOT NULL … Read more