I've done these enough now that I'd would've thought I'd have accidentally memorized it already, but thanks to the ease with which you can learn the exact syntax of any concept stuck if your head with a half-second of googling, I hadn't yet.

Anyhow, SQL Server object checks are pretty easy. All you need to know is...

IF OBJECT_ID('name') IS NOT NULL

Now you can leave out the object type and use the above for anything in your db:

IF OBJECT_ID('myFreakinView') IS NOT NULL
    DROP VIEW myFreakinView;
GO

Or you can use object types to ensure you're really getting the object type that you're checking for, in this case, a view:

IF OBJECT_ID('myFreakinView', 'V') IS NOT NULL
    DROP VIEW myFreakinView;
GO

Seems I've listed these before...

SQ = Service queue
TA = Assembly (CLR) DML trigger
TF = SQL table-valued-function
TR = SQL DML trigger
TT = Table type
U = Table (user-defined)
UQ = UNIQUE constraint
V = View
X = Extended stored procedure

In other news, my Y700 is supposed to show up today. Ordered yesterday, free shipping option, on the truck this morning. Not too shabby. Guess that's what ordering the preconfigured loadout does for you. Of course I don't think I'll be home when it arrives. ARGH. Oh well.

Labels: ,