Truncating all tables in a Postgres database

FrustratedWithFormsDesigner is correct, PL/pgSQL can do this. Here’s the script: CREATE OR REPLACE FUNCTION truncate_tables(username IN VARCHAR) RETURNS void AS $$ DECLARE statements CURSOR FOR SELECT tablename FROM pg_tables WHERE tableowner = username AND schemaname=”public”; BEGIN FOR stmt IN statements LOOP EXECUTE ‘TRUNCATE TABLE ‘ || quote_ident(stmt.tablename) || ‘ CASCADE;’; END LOOP; END; $$ LANGUAGE … Read more

Truncating long strings with CSS: feasible yet?

Update: text-overflow: ellipsis is now supported as of Firefox 7 (released September 27th 2011). Yay! My original answer follows as a historical record. Justin Maxwell has cross browser CSS solution. It does come with the downside however of not allowing the text to be selected in Firefox. Check out his guest post on Matt Snider’s … Read more

What is the command to truncate a SQL Server log file?

In management studio: Don’t do this on a live environment, but to ensure you shrink your dev db as much as you can: Right-click the database, choose Properties, then Options. Make sure “Recovery model” is set to “Simple”, not “Full” Click OK Right-click the database again, choose Tasks -> Shrink -> Files Change file type … Read more

Truncate a string straight JavaScript

Use the substring method: var length = 3; var myString = “ABCDEFG”; var myTruncatedString = myString.substring(0,length); // The value of myTruncatedString is “ABC” So in your case: var length = 3; // set to the number of characters you want to keep var pathname = document.referrer; var trimmedPathname = pathname.substring(0, Math.min(length,pathname.length)); document.getElementById(“foo”).innerHTML = “<a href=”” … Read more

What’s the difference between TRUNCATE and DELETE in SQL

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, with differences highlighted below. General Overview If you want to quickly delete all of the rows from a table, and you’re … Read more

How do I truncate a .NET string?

There isn’t a Truncate() method on string, unfortunately. You have to write this kind of logic yourself. What you can do, however, is wrap this in an extension method so you don’t have to duplicate it everywhere: public static class StringExt { public static string Truncate(this string value, int maxLength) { if (string.IsNullOrEmpty(value)) return value; … Read more