DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
 
 
SITE SEARCH SQLUSA.com VIDEOS
 
 
SQL E/BOOKS   WORLD, USA & SQL NEWS   FORMAT
SCRIPTS SQL 2005 SQL 2008 ARTICLES
How to use the EXISTS keyword in conditional expressions?

The following Microsoft SQL Server 2008 T-SQL scripts demonstrate the use of EXISTS in conditional expressions.

-- T-SQL check table existence before dropping view or table
-- Create test table with SELECT INTO
USE AdventureWorks2008;
SELECT * INTO Product1 FROM AdventureWorks2008.Production.Product
GO
-- (504 row(s) affected)
CREATE VIEW vProduct1 AS SELECT * FROM Product1
GO
IF  EXISTS (SELECT * FROM sys.views
            WHERE object_id = OBJECT_ID(N'[dbo].[vProduct1]'))
DROP VIEW [dbo].[vProduct1]
GO
IF  EXISTS (SELECT * FROM sys.objects
            WHERE object_id = OBJECT_ID(N'[dbo].[Product1]')
              AND type in (N'U'))

DROP TABLE [dbo].[Product1]
GO

-- DROP stored procedure if exists

IF EXISTS ( SELECT *

                  FROM sys.objects

                  WHERE object_id = OBJECT_ID(N'[dbo].[uspCustomerListByState]')

                              AND TYPE IN (N'P',N'PC'))

DROP PROCEDURE [dbo].[uspCustomerListByState]

GO

Exam Prep 70-461
SQL 2016 DESIGN & PROGRAMMING
 
 
 
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE