Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to delete the current database connection user

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces how to delete the current database connection users, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to know about it.

USE master

Go

IF EXISTS (SELECT *

FROM dbo.sysobjects

WHERE id = OBJECT_ID (N' [dbo]. [P_KillConnections]')

AND OBJECTPROPERTY (id, NissIsProcedure') = 1)

DROP PROCEDURE [dbo]. [P_KillConnections]

GO

CREATE PROC P_KillConnections @ dbname VARCHAR

AS

DECLARE @ sql NVARCHAR

DECLARE @ spid NVARCHAR (20)

DECLARE # tb CURSOR FOR

SELECT spid=CAST (spid AS VARCHAR 20) FROM master..sysprocesses WHERE dbid=DB_ID (@ dbname)

OPEN # tb

FETCH NEXT FROM # tb INTO @ spid

WHILE @ @ fetch_status = 0

BEGIN

EXEC ('kill' + @ spid)

FETCH NEXT FROM # tb INTO @ spid

END

CLOSE # tb

DEALLOCATE # tb

Go

-- modify it

EXEC P_KillConnections'# # enter your DBNAME

Thank you for reading this article carefully. I hope the article "how to delete the current database connection user" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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: 205

*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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report