This article is a mirror article of machine translation, please click here to jump to the original article.

View: 12958|Reply: 0

[Source] SQL method to determine if a function stored procedure exists

[Copy link]
Posted on 2020-3-24 13:33:58 | | |
The following is an introduction to the code used to judge the existence of various resources under SQL, friends who need it can refer to it, I hope it can be helpful for you to learn SQL functions and databases.
library exists
if exists(select * from master.. sysdatabases where name=N'database name')
print 'exists'
else
print 'not exists'
---------------
-- Determine if the table name to be created exists
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ table name]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
-- Delete table
drop table [dbo]. [Table Name]
GO
---------------
--Determine if the temporary table to be created exists
If Object_Id('Tempdb.dbo.#Test') Is Not Null
Begin
print 'exists'
End
Else
Begin
print 'does not exist'
End
---------------
-- Determine if the stored procedure name to be created exists
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ Stored procedure name]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
-- Delete stored procedures
drop procedure [dbo]. [stored procedure name]
GO

---------------
-- Determine if the view name to be created exists
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ View Name]') and OBJECTPROPERTY(id, N'IsView') = 1)
-- Delete view
drop view [dbo]. [View Name]
GO
---------------
-- Determine if the function name to be created exists
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ Function name]') and xtype in (N'FN', N'IF', N'TF'))
-- Delete function
drop function [dbo]. [Function Name]
GO
if col_length('table name', 'column name') is null
print 'does not exist'
select 1 from sysobjects where id in (select id from syscolumns where name='column name') and name='table name'




Previous:15 well-known foreign third-party payment platforms
Next:C# determines whether an executable is present in the Windows environment variable
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com