Heute entdeckte ich durch Zufall, dass ein ganz tolles, dokumentiertes Feature aus dem "SQL Server 2005" auch schon (undokumentiert) im "SQL Server 2000" funktioniert.

Bevor ich eine Procedure oder View anlege, prüfe ich immer zuerst, ob es sie schon gibt und lösche Sie dann gegebenenfalls. "Früher" nutzte ich dazu die Systemtabellen, Z.B. so:

if exists(select *
from sysobjects
where name = N'MyProc'
and type = N'P')
drop procedure MyProc
go
Create procedure MyProc
as
select N'tolles Beispiel' as "Info"

Nachdem ich oft genug gehört hatte, dass man keine direkten Zugriffe auf die Systemtabellen machen soll, weil sie irgendwann (Z.B. wurde mit Yukon gedroht) abgeschafft würden, habe ich das (völlig umsonst) umgestellt:

if objectproperty(object_id(N'MyProc'), 'IsProcedure') = 1
drop procedure MyProc
go
Create procedure MyProc
as
select N'tolles Beispiel' as "Info"

Heute entdeckte ich, dass auch am 2000er die Funktion object_id um den Typ erweitert werden kann:

if object_id(N'MyProc', N'P') is not null
drop procedure MyProc
go
Create procedure MyProc
as
select N'tolles Beispiel' as "Info"

Mit diesem schicken Feature aus dem 2005er ist es doch gleich viel handlicher… 🙂