Let me expand on what I am saying. New language features of T-SQL have been introduced in SQL Server 2016 such as DROP IF EXISTS and CREATE OR ALTER statements. With DROP IF EXISTS we can drop some sorts of object and validate their existence in only one statement. The objects supported with DROP IF EXISTS are PROCEDURE, TABLE (included COLUMN and CONSTRAINT), TRIGGER, VIEW, FUNCTION, INDEX, ASSEMBLY, ROLE, AGGREGATE, RULE, TYPE, DATABASE, SCHEMA, USER, DEFAULT, SECURITY POLICY, SEQUENCE, and SYNONYM. Thus we do not need to do something like this any longer.
IF EXISTS (SELECT * FROM sys.objects WHERE name = 'MyProcNumberOne') DROP PROCEDURE MyProcNumberOne
DROP PROCEDURE IF EXISTS [dbo].[MyProcNumberOne] GO DROP TABLE IF EXISTS [dbo].[MyTableDemo] GO DROP VIEW IF EXISTS [dbo].[MyViewTest] GO DROP VIEW IF EXISTS [dbo].[MyFunctionTwo] GO DROP INDEX IF EXISTS [dbo].[IX_MyTableDemo_04]
ALTER TABLE [dbo].[MyTableDemo] DROP COLUMN IF EXISTS Col2 GO ALTER TABLE [dbo].[MyTableDemo] DROP CONSTRAINT IF EXISTS FK_MyTableDemo_10 GO
Now talking of the other new statement CREATE OR ALTER, it supports STORED PROCEDURES (including natively compiled), FUNCTIONS (including natively compiled), TRIGGERS, and VIEWS. So we are not going to need the traditional validation any more.
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MyProcNumberOne]') CREATE PROCEDURE dbo.mysproc (@Par1 INT, @Par2 VARCHAR(10), ... ) AS BEGIN ... ..
CREATE OR ALTER [dbo].[MyProcNumberOne] (@Par1 INT, @Par2 VARCHAR(10), ... ) AS BEGIN ... ..
To be perfectly honest, I do think that these new language features are the be-all and end-all as they are practical, simple and allow us to work in the sense of improving the quality of deploying new business functionalities and integration of systems. Surely, you will make the most out of these features. That is all for now. Let me know any remarks you may have. Thanks for reading.
No comments:
Post a Comment
Let me know any remarks or questions you may have. Please write down your name.