Object_id () vs sys.objects

I use database scripts where I check for a stored procedure, then drop it and create it.

Which of the following would be more effective in verifying and removing SPs
Option 1

IF EXISTS(SELECT * FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'[dbo].[myStoredProc]',N'P'))
  DROP PROCEDURE dbo.myStoredProc;

Option 2

IF OBJECT_ID (N'dbo. myStoredProc',N'P') IS NOT NULL
  DROP PROCEDURE dbo.myStoredProc;

I decided to use the second because of obvious reasons, is there any reason I should go for the first option

+3
source share
2 answers

No, there is no good reason to use sys.object directly. Essentially, using these sys views is discouraged, so if you can avoid it, do it!

, INFORMATION_SCHEMA, , - SQL-92 ( Microsoft, sys. *).

+1

. MSDN , sys.object INFORMATION_SCHEMA, sys , .

+2

Source: https://habr.com/ru/post/1707232/


All Articles