0
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?

Django バックエンド開発時によく使った Azure SQL Database コマンド一覧

Posted at
  • バージョン確認

    SELECT @@VERSION AS SQLServerVersion;
    
  • カレントデータベース名を取得

    SELECT DB_NAME() AS CurrentDatabase;
    
  • スキーマの作成

    CREATE SCHEMA dev;
    
  • スキーマ一覧を取得

    SELECT name AS SchemaName
    FROM sys.schemas;
    
  • カレントスキーマ名を取得

    SELECT SCHEMA_NAME() AS CurrentSchema;
    
  • カレントユーザー名を取得

    SELECT SUSER_NAME() AS CurrentLogin;
    
  • ユーザーの一覧を取得

    SELECT name, type_desc, create_date, modify_date
    FROM sys.database_principals
    ORDER BY name;
    
  • SQL 認証用のユーザーアカウントを作成

    CREATE LOGIN <your-login-name>
    WITH PASSWORD = '<password>';
    
    CREATE USER <your-user-name>
    FOR LOGIN <your-login-name>;
    
  • ユーザーのデフォルトスキーマを変更

    ALTER USER [<your-user-name>] WITH DEFAULT_SCHEMA = dev;
    
  • 任意のユーザーにロールを付与

    GRANT SELECT, INSERT, UPDATE, DELETE, ALTER ON SCHEMA::dev TO <your-user-name>;
    
  • 任意のユーザーに付与したロールを削除

    REVOKE INSERT, UPDATE, DELETE, SELECT, ALTER ON SCHEMA::dev FROM [<your-user-name>];
    
  • 任意のユーザーに DDL 実行権限を付与

    ALTER ROLE db_ddladmin ADD MEMBER [<your-user-name>];
    
  • ユーザーのロール一覧を取得

    SELECT
        dp.name AS UserName,
        dp.type_desc AS UserType,
        dr.permission_name AS PermissionName,
        dr.state_desc AS PermissionState
    FROM sys.database_principals dp
    LEFT JOIN sys.database_permissions dr ON dp.principal_id = dr.grantee_principal_id
    WHERE dp.name = '<your-user-name>';
    
    
0
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
0
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?