April 2008 Entries
By adding a top clause to your delete statement you can delete a chunk of records at a time. By combining it with a while you can put it in a loop and wipe the entire table.
WHILE EXISTS (SELECT * FROM Foo)
DELETE TOP(100) FROM Foo
Had someone send me an email telling me that it might be better to use a TRUNCATE TABLE command then this method, and in most cases this is preferable. Conversly not always do us "evil" developers get TRUNCATE permissions from our DBA's. You can read more about TRUNCATE here (http://msdn2.microsoft.com/en-us/library/aa260621.aspx).
Got a question from an attendee at the Orlando Launch Event, he wanted to know how to change the colors of a button from code (i.e. the click event). Both of these items are properties on the button and can be changed easily with the following code.
button1.ForeColor = System.Drawing.Color.Blue;button1.BackColor = System.Drawing.Color.Yellow;
At the last ONETUG meeting a question came up how to force WCF to use Windows Auth (i.e. Kerberos). By default WCF is in negotiate mode. While this is good for many cases where you cannot ensure that Kerberos will be available if you are in an intranet environment where you know it will be you can speed up your service by skipping the negotiation phase. Matevz Gacnik has a good sample in his blog (http://www.request-response.com/blog/PermaLink,guid,4b5f46cd-3c15-4213-9570-1a235c4a615e.aspx) using certificates, the only change is to set the clientCredentialType to “Windows”.
<bindings> <wsHttpBinding> <binding name="MySecureBinding"> <security mode ="Message"> <message clientCredentialType="Windows" negotiateServiceCredential="false"/> </security> </binding> </wsHttpBinding></bindings>
I was trying to get rid of all the objects (tables, procedures, views) in my database and whipped up this little script and while it is far from perfect it is well worth sharing. . .
SELECT CASE WHEN type = 'P' THEN 'DROP PROCEDURE ' + name WHEN type = 'U' THEN 'DROP TABLE ' + name WHEN type = 'V' THEN 'DROP VIEW ' + name WHEN type = 'FN' THEN 'DROP FUNCTION ' + name ELSE '' END AS dropSQL, * FROM sys.objects WHERE type != 'S' AND type != 'IT' AND type != 'SQ'