当前位置:网站首页>SQL server deletes all tables and all stored procedures in the database
SQL server deletes all tables and all stored procedures in the database
2022-06-13 02:01:00 【Sima Yi】
scene :
SQL Server in , When you need to delete all tables or all stored procedures , The manual method can only delete one by one , Personal time consuming , So I want to make a statement to realize such a requirement .
If deleted due to foreign key constraints table Failure , Delete all constraints first :
--/ The first 1 Step ********** Delete foreign key constraints for all tables *************************/
DECLARE c1 cursor for
select 'alter table ['+ object_name(parent_obj) + '] drop constraint ['+name+']; '
from sysobjects
where xtype = 'F'
open c1
declare @c1 varchar(8000)
fetch next from c1 into @c1
while(@@fetch_status=0)
begin
exec(@c1)
fetch next from c1 into @c1
end
close c1
deallocate c1
go
--/ The first 2 Step ********** Delete all tables *************************/
use database
declare @tname varchar(8000)
set @tname=''
select @[email protected] + Name + ',' from sysobjects where xtype='U'
select @tname='drop table ' + left(@tname,len(@tname)-1)
exec(@tname)
go
Deleting all stored procedures is the same , But there is no need to take the first step , Just put the second 2 Code of step where xtype='U' Change to where xtype='P',drop table Change to drop Procedure
sysobjects Of xtype Means :
Every object created in the database ( constraint 、 The default value is 、 journal 、 The rules 、 Stored procedure, etc ) Take a row in the table . Only in tempdb Inside , Each temporary object occupies only one row in the table .
Name data type describe
name sysname Object name .
Id int Object identification number .
xtype char(2) object type . It can be one of the following object types :
C = CHECK constraint
D = Default value or DEFAULT constraint
F = FOREIGN KEY constraint
L = journal
FN = Scalar function
IF = Embedded table functions
P = stored procedure
PK = PRIMARY KEY constraint ( The type is K)
RF = Copy filter stored procedure
S = The system tables
TF = Table function
TR = trigger
U = User table
UQ = UNIQUE constraint ( The type is K)
V = View
X = Extended stored procedure
uid smallint The user of the owner object ID.
info smallint Retain . Internal use only .
status int Retain . Internal use only .
base_schema_
ver int Retain . Internal use only .
replinfo int Retain . For replication .
parent_obj int The object identification number of the parent object ( for example , For triggers or constraints , The identification number is table ID).
crdate datetime The creation date of the object .
ftcatid smallint Full text catalog identifier for all user tables registered for full-text indexing , For all users who are not registered, the table is 0.
schema_ver int Version number , The version number is incremented every time the schema of the table changes .
stats_schema_
ver int Retain . Internal use only .
type char(2) object type . It can be one of the following values :
C = CHECK constraint
D = Default value or DEFAULT constraint
F = FOREIGN KEY constraint
FN = Scalar function
IF = Embedded table functions
K = PRIMARY KEY or UNIQUE constraint
L = journal
P = stored procedure
R = The rules
RF = Copy filter stored procedure
S = The system tables
TF = Table function
TR = trigger
U = User table
V = View
X = Extended stored procedure
userstat smallint Retain .
sysstat smallint Internal status information .
indexdel smallint Retain .
refdate datetime For later use .
version int For later use .
deltrig int Retain .
instrig int Retain .
updtrig int Retain .
seltrig int Retain .
category int For publishing 、 Constraints and identification .
cache smallint Retain .
边栏推荐
- [learning notes] xr872 audio driver framework analysis
- 分享三个关于CMDB的小故事
- Introduction to ROS runtime
- 华为设备配置私网IP路由FRR
- Matplotlib drawing Chinese garbled code
- Installing pytorch geometric
- TensorFlow2的Conv1D, Conv2D,Conv3D机器对应的MaxPooling详解
- Restrict cell input type and display format in CXGRID control
- Plumber game
- How do you use your own data to achieve your marketing goals?
猜你喜欢

The scientific innovation board successfully held the meeting, and the IPO of Kuangshi technology ushered in the dawn

传感器:MQ-5燃气模块测量燃气值(底部附代码)

DFS and BFS to solve Treasure Island exploration

Ctrip reshapes new Ctrip

Numpy multidimensional array transpose transpose

Stm32+ze-08 formaldehyde sensor tutorial

Stm32 3*3 matrix key (register version)

Workspace for ROS
![[learning notes] xr872 audio driver framework analysis](/img/1a/008a89f835dc1b350a1f1ff27bee00.jpg)
[learning notes] xr872 audio driver framework analysis

Alertwindowmanager pop up prompt window help (Part 1)
随机推荐
华为设备配置IP和虚拟专用网混合FRR
Installing pytorch geometric
Functional translation
What is Google plus large text ads? How to use it?
Mac下搭建MySQL环境
How many smart bids does Google have?
In the third quarter, the revenue and net profit increased "against the trend". What did vatti do right?
华为设备配置虚拟专用网FRR
(no plug-in) summary of vim basic shortcut keys
蓝牙模块:使用问题集锦
TensorFlow 2. X multi graphics card distributed training
Detailed explanation of maxpooling corresponding to conv1d, conv2d and conv3d machines of tensorflow2
什么是立体角
Numpy multidimensional array transpose transpose
Magics 23.0如何激活和使用视图工具页的切片预览功能
6、 Implementation of warehouse out management function
16 embedded C language interview questions (Classic)
Simple ranging using Arduino and ultrasonic sensors
Qt实现思维导图功能(二)
Magics 23.0 how to activate and use the slice preview function of the view tool page