In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how sql judges the existence of databases, tables, stored procedures, etc." in daily operation, I believe many people have doubts about how to judge databases, tables, stored procedures, etc. In daily operation, the editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for everyone to answer the doubts of "how to judge databases, tables, stored procedures, etc." by sql. Next, please follow the editor to study!
Code:
-- whether there is an if exists (select * from master..sysdatabases where name=N' library name') print 'exists'elseprint' not exists'- to determine whether an if exists exists in the table name to be created (select * from dbo.sysobjects where id = object_id (N' [dbo]). [table name]') and OBJECTPROPERTY (id, NabilisUserTable') = 1)-Delete table drop table [dbo]. [table name] whether IF COL_LENGTH exists in the GO- column ('table name') 'column name') IS NULL PRINT 'not exists'ELSE PRINT' exists'alter table table name drop constraint default name goalter table table name drop column column name go- determines whether temporary table exists If Object_Id ('Tempdb.dbo.#Test') Is Not NullBeginprint' exists' EndElseBeginprint 'does not exist' End- determines whether 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, NumbIsProcedure') = 1)-Delete stored procedure drop procedure [dbo]. [stored procedure name] GO- determines whether if exists exists in the view name to be created (select * from dbo.sysobjects where id = object_id (N' [dbo]). [view name]') and OBJECTPROPERTY (id, Noble IsView') = 1)-Delete view drop view [dbo]. [view name] GO- determines whether the function name to be created has if exists (select * from sysobjects where xtype='fn' and name=' function name') if exists (select * from dbo.sysobjects where id = object_id (N' [dbo]). [function name]') and xtype in (drop function FNN, NFN, NFF')-Delete the function drop function [dbo]. [function name] GOif col_length ('table name', 'column name') is nullprint 'does not exist' select 1 from sysobjects where id in (select id from syscolumns where name=' column name') and name=' table name'
Sql judges whether it exists or not.
-- determine whether if exists (select * from master..sysdatabases where name=N' library name') print 'exists' else print' not exists' exists in the database-- determine whether there is if exists in the table name to be created (select * from dbo.sysobjects where id = object_id (N' [dbo]). [table name]') and OBJECTPROPERTY (id, NabilisUserTable') = 1)-Delete table drop table [dbo]. [table name] GO-to determine whether 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 whether 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, NumbIsProcedure') = 1)-Delete stored procedure drop procedure [dbo]. [stored procedure name] GO-determines whether if exists exists in the view name to be created (select * from dbo.sysobjects where id = object_id (N' [dbo]. [view name]') and OBJECTPROPERTY (id, Noble IsView') = 1)-Delete view drop view [dbo]. [view name] GO-determine whether if exists exists in the function name to be created (select * from dbo.sysobjects where id = object_id (N' [dbo]. [function name]') and xtype in (drop function FNN, NFN, NFF')-Delete the 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'so far, the study on "how sql determines the existence of databases, tables, stored procedures, etc." is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.