1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

DBのユーザー権限はく奪手順

Posted at

SQLサーバー内でユーザー権限をはく奪するのに使用したコード一覧メモ

ユーザーがどのテーブルのどの権限を持っているか確認

DBを指定
USE [sampleDB]

SELECT
    USER_NAME(grantee_principal_id) AS ユーザー名,
    class_desc AS クラス,
    OBJECT_NAME(major_id) AS オブジェクト名,
    permission_name as 権限名
FROM sys.database_permissions
WHERE grantee_principal_id = USER_ID('sampleDbRole') --ユーザー名 or ロール名を指定

はく奪用コード(ALTERはALLだと消えなかったので別枠)

DBを指定
USE [sampleDB]

REVOKE ALL ON [テーブル名] TO [ユーザー名];
REVOKE ALTER ON [テーブル名] TO [ユーザー名];

SELECT
    USER_NAME(grantee_principal_id) AS ユーザー名,
    class_desc AS クラス,
    OBJECT_NAME(major_id) AS オブジェクト名,
    permission_name as 権限名
FROM sys.database_permissions
WHERE grantee_principal_id = USER_ID('sampleDbRole') --ユーザー名 or ロール名を指定

DATABASEクラスのCONNECT権限をはく奪するコード

DBを指定
USE [sampleDB]

REVOKE CONNECT ON DATABASE::KENPO_DB TO ユーザー名;


SELECT
    USER_NAME(grantee_principal_id) AS ユーザー名,
    class_desc AS クラス,
    OBJECT_NAME(major_id) AS オブジェクト名,
    permission_name as 権限名
FROM sys.database_permissions
WHERE grantee_principal_id = USER_ID('sampleDbRole') --ユーザー名 or ロール名を指定
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?