共用方式為


DatabaseRoles Collection

未來的 Microsoft SQL Server 發行版本將不再提供此功能。請避免在新的開發工作中使用此功能,並計劃修改目前使用此功能的應用程式。

The DatabaseRoles collection contains DatabaseRole objects that expose Microsoft SQL Server security privilege roles defined within a database.

顯示目前物件的 SQL-DMO 物件模型

Methods

Add Method

Refresh Method

Item Method

Remove Method (Collections)

備註

A SQL Server database role can contain one or more members (database users). A properly authenticated user can create database roles; add members or remove them from the role; and grant or deny database privileges to the role to administer privileges for one or more users, logically organized. With the DatabaseRoles collection, you can:

  • Create a SQL Server database role.
  • Remove a SQL Server database role.

For more information about creating database roles, see the DatabaseRole Objectsection.

To remove a database role

  1. Use the DropMember method of the DatabaseRole object to remove all members from the role.

  2. Use the Remove method of the DatabaseRoles collection to remove the role from the SQL Server database, as in:

    oDatabase.DatabaseRoles.Remove("Clerical")
    
    ms135658.note(zh-tw,SQL.90).gif附註:
    You cannot remove a database role from a SQL Server database if the role contains members. The EnumDatabaseRoleMember method of the DatabaseRole object can be used to list the current members of a role. Use the results of the method to remove members, then remove the role.

When using the Item or Remove method, the DatabaseRoles collection supports member identification using either name or ordinal reference syntax. For example:

Set oDatabaseRole = oDatabase.DatabaseRoles("Clerical")

Or

Set oDatabaseRole = oDatabase.DatabaseRoles(4)
ms135658.note(zh-tw,SQL.90).gif附註:
Inspecting or modifying database roles using the DatabaseRoles collection requires appropriate privilege. The SQL Server login used for SQLServer object connection must be a member of the fixed role db_securityadmin or a role with greater privilege.