CREATE DATABASE SCOPED CREDENTIAL (Transact-SQL)
Updated: January 9, 2017
Creates a database credential. A database credential is not mapped to a server login or database user. The credential is used by the database to access to the external location anytime the database is performing an operation that requires access.
CREATE DATABASE SCOPED CREDENTIAL credential_name WITH IDENTITY = 'identity_name' [ , SECRET = 'secret' ]
Specifies the name of the database scoped credential being created. credential_name cannot start with the number (#) sign. System credentials start with ##.
Specifies the name of the account to be used when connecting outside the server. To import a file from Azure Blob storage, the identity name must be
SHARED ACCESS SIGNATURE. For more information about shared access signatures, see Using Shared Access Signatures (SAS).
Specifies the secret required for outgoing authentication.
SECRET is required to import a file from Azure Blob storage.
The SAS key value might begin with a '?' (question mark). When you use the SAS key, you must remove the leading '?'. Otherwise your efforts might be blocked.
A database scoped credential is a record that contains the authentication information that is required to connect to a resource outside SQL Server. Most credentials include a Windows user and password.
Before creating a database scoped credential, the database must have a master key to protect the credential. For more information, see CREATE MASTER KEY (Transact-SQL).
When IDENTITY is a Windows user, the secret can be the password. The secret is encrypted using the service master key. If the service master key is regenerated, the secret is re-encrypted using the new service master key.
Information about database scoped credentials is visible in the sys.database_credentials (Transact-SQL) catalog view.
Hereare some applications of database scoped credentials:
SQL Server uses a database scoped credential to access non-public Azure blob storage or Kerberos-secured Hadoop clusters with PolyBase. To learn more, see CREATE EXTERNAL DATA SOURCE (Transact-SQL).
SQL Data Warehouse uses a database scoped credential to access non-public Azure blob storage with PolyBase. To learn more, see CREATE EXTERNAL DATA SOURCE (Transact-SQL).
SQL Database uses database scoped credentials for its global query feature. This is the ability to query across multiple database shards.
SQL Database uses database scoped credentials to write extended event files to Azure blob storage.
SQL Database uses database scoped credentials for elastic pools. For more information, see Tame explosive growth with elastic databases
BULK INSERT and OPENROWSET use database scoped credentials to access data from Azure blob storage. For more information, see Examples of Bulk Access to Data in Azure Blob Storage.
Requires CONTROL permission on the database.
The following example creates the database scoped credential called
AppCred. The database scoped credential contains the Windows user
Mary5 and a password.
-- Create a db master key if one does not already exist, using your own password. CREATE MASTER KEY ENCRYPTION BY PASSWORD='<EnterStrongPasswordHere>'; -- Create a database scoped credential. CREATE DATABASE SCOPED CREDENTIAL AppCred WITH IDENTITY = 'Mary5', SECRET = '<EnterStrongPasswordHere>'; GO
CREATE DATABASE SCOPED CREDENTIAL MyCredentials WITH IDENTITY = 'SHARED ACCESS SIGNATURE', SECRET = 'QLYMgmSXMklt%2FI1U6DcVrQixnlU5Sgbtk1qDRakUBGs%3D';
Credentials (Database Engine)
ALTER DATABASE SCOPED CREDENTIAL (Transact-SQL)
DROP DATABASE SCOPED CREDENTIAL (Transact-SQL)
CREATE CREDENTIAL (Transact-SQL)