Aracılığıyla paylaş


Database Class

Represents an SQL Server database.

Inheritance Hierarchy

System.Object
  Microsoft.SqlServer.Management.Smo.SmoObjectBase
    Microsoft.SqlServer.Management.Smo.SqlSmoObject
      Microsoft.SqlServer.Management.Smo.NamedSmoObject
        Microsoft.SqlServer.Management.Smo.ScriptNameObjectBase
          Microsoft.SqlServer.Management.Smo.Database

Namespace:  Microsoft.SqlServer.Management.Smo
Assembly:  Microsoft.SqlServer.Smo (in Microsoft.SqlServer.Smo.dll)

Syntax

'Bildirim
<PhysicalFacetAttribute> _
<EvaluationModeAttribute(AutomatedPolicyEvaluationMode.CheckOnSchedule)> _
Public NotInheritable Class Database _
    Inherits ScriptNameObjectBase _
    Implements ICreatable, IAlterable, IDroppable, IRenamable,  _
    IExtendedProperties, IScriptable, IDatabaseOptions, IDmfFacet, ISfcSupportsDesignMode
'Kullanım
Dim instance As Database
[PhysicalFacetAttribute]
[EvaluationModeAttribute(AutomatedPolicyEvaluationMode.CheckOnSchedule)]
public sealed class Database : ScriptNameObjectBase, 
    ICreatable, IAlterable, IDroppable, IRenamable, IExtendedProperties, 
    IScriptable, IDatabaseOptions, IDmfFacet, ISfcSupportsDesignMode
[PhysicalFacetAttribute]
[EvaluationModeAttribute(AutomatedPolicyEvaluationMode::CheckOnSchedule)]
public ref class Database sealed : public ScriptNameObjectBase, 
    ICreatable, IAlterable, IDroppable, IRenamable, IExtendedProperties, 
    IScriptable, IDatabaseOptions, IDmfFacet, ISfcSupportsDesignMode
[<SealedAttribute>]
[<PhysicalFacetAttribute>]
[<EvaluationModeAttribute(AutomatedPolicyEvaluationMode.CheckOnSchedule)>]
type Database =  
    class
        inherit ScriptNameObjectBase
        interface ICreatable
        interface IAlterable
        interface IDroppable
        interface IRenamable
        interface IExtendedProperties
        interface IScriptable
        interface IDatabaseOptions
        interface IDmfFacet
        interface ISfcSupportsDesignMode
    end
public final class Database extends ScriptNameObjectBase implements ICreatable, IAlterable, IDroppable, IRenamable, IExtendedProperties, IScriptable, IDatabaseOptions, IDmfFacet, ISfcSupportsDesignMode

The Database type exposes the following members.

Constructors

  Name Description
Public method Database() Initializes a new instance of the Database class.
Public method Database(Server, String) Initializes a new instance of the Database class on the specified server and with the specified name.

Top

Properties

  Name Description
Public property ActiveConnections Gets the number of active connections to the database.
Public property ActiveDirectory Obsolete. Gets the information about the Active Directory settings for the database.
Public property AnsiNullDefault Gets or sets a value that specifies whether the ANSI_NULL_DEFAULT database option is active.
Public property AnsiNullsEnabled Gets or sets a value that specifies whether the ANSI_NULLS_ENABLED database option is active.
Public property AnsiPaddingEnabled Gets or sets a value that specifies whether the ANSI_PADDING_ENABLED database option is active.
Public property AnsiWarningsEnabled Gets or sets a value that specifies whether the ANSI_WARNINGS_ENABLED database option is active.
Public property ApplicationRoles Gets a collection of ApplicationRole objects. Each ApplicationRole object represents an application role defined on the database.
Public property ArithmeticAbortEnabled Gets or sets a value that specifies whether the ARITHMETICABORT database option is active.
Public property Assemblies Gets a collection of SqlAssembly objects. Each SqlAssembly object represents an assembly defined on the database.
Public property AsymmetricKeys Gets a collection of AsymmetricKey objects. Each AsymmetricKey object represents an asymmetric key defined on the database.
Public property AutoClose Gets or sets a value that specifies whether the AUTOCLOSE database option is set.
Public property AutoCreateStatisticsEnabled Gets a value that specifies whether statistics are automatically created for the database.
Public property AutoShrink Gets or sets a value that specifies whether the AUTO_SHRINK database option is active.
Public property AutoUpdateStatisticsAsync Gets or sets a value that specifies whether the AUTOUPDATESTATISTICSASYNC database option is active.
Public property AutoUpdateStatisticsEnabled Gets or sets a value that specifies whether statistics are automatically updated for the database.
Public property AvailabilityDatabaseSynchronizationState Gets the synchronization state of the availability database.
Public property AvailabilityGroupName Gets the availability group name in the database.
Public property BrokerEnabled Gets or sets a value that specifies whether the Service Broker service is enabled.
Public property CaseSensitive Gets a value that specifies whether uppercase letters and lowercase letters are evaluated as equal.
Public property Certificates Gets a collection of Certificate objects. Each Certificate object represents a certificate defined on the database.
Public property ChangeTrackingAutoCleanUp Gets or sets a value that specifies whether the CHANGE_TRACKING_AUTO_CLEANUP OPTION is enabled.
Public property ChangeTrackingEnabled Gets or sets a value that specifies whether the CHANGE_TRACKING_VALUE option is enabled
Public property ChangeTrackingRetentionPeriod Gets or sets the CHANGE_TRACKING_RETENTION_PERIOD value.
Public property ChangeTrackingRetentionPeriodUnits Gets or sets the unit type for a retention period value.
Public property CloseCursorsOnCommitEnabled Gets or sets a value that specifies whether the CURSOR_CLOSE_ON_COMMIT database option is active.
Public property Collation Gets or sets the default collation used by the database.
Public property CompatibilityLevel Gets or sets the compatibility level for the database.
Public property ConcatenateNullYieldsNull Gets or sets a value that specifies whether the CONCAT_NULL_YIELDS_NULL database option is active.
Public property ContainmentType Gets or sets the type of containment.
Public property CreateDate Gets the date that the database was created.
Public property DatabaseAuditSpecifications Gets a collection of DatabaseAuditSpecification objects. Each DatabaseAuditSpecification object represents a database audit specification defined on the server.
Public property DatabaseEncryptionKey Gets a DataBaseEncryptionKey data type.
Public property DatabaseGuid Gets the Guid value that uniquely identifies the database.
Public property DatabaseOptions Gets the DatabaseOptions object that contains configuration options for the database.
Public property DatabaseOwnershipChaining Gets or sets a value that specifies whether the database ownership chaining is active.
Public property DatabaseSnapshotBaseName Gets the name of the snapshot base for the database.
Public property DataSpaceUsage Gets the space used by the data in the database.
Public property DateCorrelationOptimization Gets or sets a value that specifies whether the date correlation optimization is active.
Public property DboLogin Gets a value that specifies whether the current user is logged on as the database owner (DBO).
Public property DefaultFileGroup Gets the default file group used by the database.
Public property DefaultFileStreamFileGroup Gets the file group name for the default file stream.
Public property DefaultFullTextCatalog Gets the default full-text catalog used by the database.
Public property DefaultFullTextLanguage Gets the default full text language.
Public property DefaultLanguage Gets or sets the default language.
Public property Defaults Gets a collection of Default objects. Each Default object represents a default defined on the database.
Public property DefaultSchema Gets the default schema of the user.
Public property EncryptionEnabled Gets or sets a value that indicates whether the data encryption is enabled.
Public property Events Gets the events associated with the database.
Protected property ExecuteForScalar Gets or sets the Boolean property value that specifies whether the object is set to the execute for scalar option. (Inherited from SqlSmoObject.)
Public property ExtendedProperties Gets the extended properties of the database.
Public property ExtendedStoredProcedures Gets a collection of ExtendedStoredProcedure objects. Each ExtendedStoredProcedure object represents an extended stored procedure defined on the database.
Public property Federations Gets a collection of Federation objects. Each Federation represents a data being partitioned on the database.
Public property FileGroups Gets a collection of FileGroup objects. Each FileGroup object represents a file group defined on the database.
Public property FilestreamDirectoryName Gets or sets the name of file stream share directory.
Public property FilestreamNonTransactedAccess Gets or sets the file stream non-transacted access setting for database.
Public property FullTextCatalogs Gets a collection of FullTextCatalog objects. Each FullTextCatalog object represents a full-text catalog defined on the database.
Public property FullTextStopLists Gets a collection of FullTextStopList objects. Each FullTextStopList object represents a full text stop list defined on the server.
Public property HonorBrokerPriority Gets or sets a value that specifies whether the priority specified by the broker is acknowledged or not.
Public property ID Gets the database ID value that uniquely identifies the database.
Public property IndexSpaceUsage Gets the space used by the indexes in the database.
Public property IsAccessible Gets a value that specifies whether the database can be accessed.
Public property IsDatabaseSnapshot Gets a value that specifies whether the database is a snapshot database.
Public property IsDatabaseSnapshotBase Gets a value that specifies whether the database is the base database for a snapshot database.
Public property IsDbAccessAdmin Gets a value that specifies whether the current user is a member of the DbAccessAdmin database role.
Public property IsDbBackupOperator Gets a value that specifies whether the current user is a member of the DbBackupOperator database role.
Public property IsDbDatareader Gets a value that specifies whether the current user is a member of the DbDatareader database role.
Public property IsDbDatawriter Gets a value that specifies whether the current user is a member of the DbDatawriter database role.
Public property IsDbDdlAdmin Gets a value that specifies whether the current user is a member of the DbDdlAdmin database role.
Public property IsDbDenyDatareader Gets a value that specifies whether the current user is a member of the DbDenyDatareader database role.
Public property IsDbDenyDatawriter Gets a value that specifies whether the current member is a member of the DbDenyDatawriter database.
Public property IsDbManager Gets a value that specifies whether the current login is a database manager in SQL Azure.
Public property IsDbOwner Gets a value that specifies whether the current user is a member of the DbOwner database role.
Public property IsDbSecurityAdmin Gets a value that specifies whether the current user is a member of the DbSecurityAdmin database role.
Public property IsFederationMember Gets or sets a value that specifies whether the database is a member of federation.
Public property IsFullTextEnabled Gets or sets a value that specifies whether the database is enabled for full-text search.
Public property IsLoginManager Gets a value that specifies whether the current login is a login manager in SQL Azure.
Public property IsMailHost Gets a value that specifies whether the database is configured as a mail host.
Public property IsManagementDataWarehouse Gets a value that specifies whether the database is a management data warehouse.
Public property IsMirroringEnabled Gets a value that specifies whether mirroring is enabled on the database.
Public property IsParameterizationForced Gets or sets a value that specifies whether parameterization is forced on the database.
Public property IsReadCommittedSnapshotOn Gets or sets a value that specifies whether transactions with the read committed isolation level use row versioning.
Public property IsSystemObject Gets a value that specifies whether the database is a system object or a user-defined database.
Protected property IsTouched Gets the Boolean property value that specifies whether the object properties have been updated but not yet persisted on the server. (Inherited from SqlSmoObject.)
Public property IsUpdateable Gets a value that specifies whether the database can be updated.
Public property IsVarDecimalStorageFormatEnabled Gets or sets a value that specifies whether VarDecimal storage is enabled.
Public property LastBackupDate Gets the date and time when the database was last backed up.
Public property LastDifferentialBackupDate Gets the date and time when the last differential backup was performed.
Public property LastLogBackupDate Gets the date and time when the transaction log was last backed up.
Public property LocalCursorsDefault Gets or sets a value that specifies whether the local server cursors are used by default.
Public property LogFiles Gets a collection of LogFile objects. Each LogFile object represents a log file defined on the database.
Public property LogReuseWaitStatus Gets the type of operation on which the reuse of transaction log space is waiting.
Public property MasterKey Gets the master key that is used to encrypt the private keys of certificates.
Public property MirroringFailoverLogSequenceNumber Gets the log sequence number at last failover.
Public property MirroringID Gets the ID value that uniquely identifies the mirroring partnership.
Public property MirroringPartner Gets or sets the address of the Database Engine instance that is the partner server for database mirroring.
Public property MirroringPartnerInstance Gets the instance of SQL Server on which the mirroring partner is configured.
Public property MirroringRedoQueueMaxSize Gets the maximum size of the redo queue of the mirror server instance in KB.
Public property MirroringRoleSequence Gets the role sequence number for primary/backup roles played by the mirroring partners.
Public property MirroringSafetyLevel Gets or sets the mirroring safety level.
Public property MirroringSafetySequence Gets the role sequence number for safety levels for the mirroring partners.
Public property MirroringStatus Gets the status of the database and the database mirroring session.
Public property MirroringTimeout Gets or sets the maximum time, in seconds, that the principal server instance waits for a PING message from another instance in the mirroring session before assuming the other instance is disconnected.
Public property MirroringWitness Gets or sets the name of the Database Engine instance of the database mirroring witness server.
Public property MirroringWitnessStatus Gets the status of the mirroring witness server.
Public property Name Gets or sets the name of the database. (Overrides NamedSmoObject.Name.)
Public property NestedTriggersEnabled Gets or sets a value that indicates whether the nested triggers are enabled.
Public property NumericRoundAbortEnabled Gets or sets a value that specifies whether the NUMERIC_ROUNDABORT database option is active.
Protected property ObjectInSpace Gets the Boolean property value that specifies whether the object exists in isolation, or whether it is directly or indirectly connected to the instance of SQL Server. (Inherited from SqlSmoObject.)
Public property Owner Gets the database principal that is the owner of the database.
Public property PageVerify Gets or sets the type of page integrity check that SQL Server performs when reading database pages.
Public property Parent Gets or sets the Server object that is the parent of the Database object.
Public property PartitionFunctions Gets a collection of PartitionFunction objects. Each PartitionFunction object represents a partition function defined on the database.
Public property PartitionSchemes Gets a collection of PartitionScheme objects. Each PartitionScheme object represents a partition scheme defined on the database.
Public property PlanGuides Gets a collection of plan guides associated with a database.
Public property PrimaryFilePath Gets the operating system directory that contains the primary file for the database.
Public property Properties Gets a collection of Property objects that represent the object properties. (Inherited from SqlSmoObject.)
Public property QuotedIdentifiersEnabled Gets or sets a value that specifies whether identifiers delimited by double quotation marks (" ") are Transact-SQL reserved keywords or contain characters not usually allowed by the Transact-SQL syntax rules.
Public property ReadOnly Gets or sets a value that specifies whether the database is read-only.
Public property RecoveryForkGuid Gets the GUID value that specifies the recovery fork on which the database is currently active.
Public property RecoveryModel Gets or sets the recovery model for the database.
Public property RecursiveTriggersEnabled Gets or sets a value that specifies whether recursive triggers are enabled on the database.
Public property ReplicationOptions Gets the active replication settings for a database.
Public property Roles Gets a collection of DatabaseRole objects. Each DatabaseRole object represents a role defined on the database.
Public property Rules Gets a collection of Rule objects. Each Rule object represents a rule defined on the database.
Protected property ScalarResult Gets the scalar result for the referenced object. (Inherited from SqlSmoObject.)
Public property Schemas Gets a collection of Schema objects. Each Schema object represents a schema defined on the database.
Public property SearchPropertyLists Gets the SearchPropertyListCollection associated with this object.
Public property Sequences Gets the SequenceCollection associated with this object.
Public property ServiceBroker Gets the ServiceBroker object that represents the Service Broker.
Public property ServiceBrokerGuid Gets the Guid object that uniquely identifies the instance of Service Broker.
Public property Size Gets the size of the database in MB.
Public property SnapshotIsolationState Gets the snapshot isolation state for the database.
Public property SpaceAvailable Gets the available space in the database in KB.
Public property State Gets the state of the referenced object. (Inherited from SmoObjectBase.)
Public property Status Gets the database status.
Public property StoredProcedures Gets a collection of StoredProcedure objects. Each StoredProcedure object represents a stored procedure defined on the database.
Public property SymmetricKeys Gets a collection of SymmetricKey objects. Each SymmetricKey object represents a symmetric key defined on the database.
Public property Synonyms Gets a collection of Synonym objects. Each Synonym object represents a synonym defined on the database.
Public property Tables Gets a collection of Table objects. Each Table object represents a table defined on the database.
Public property TargetRecoveryTime Gets or sets the target recovery time of the used database.
Public property TransformNoiseWords Gets a value that indicates whether an object that sets the transform noise words configuration option is used.
Public property Triggers Gets a collection of DatabaseDdlTrigger objects. Each DatabaseDdlTrigger object represents a trigger defined on the database.
Public property Trustworthy Gets or sets a value that indicates whether the instance of SQL Server 2005 trusts the database and the contents within it.
Public property TwoDigitYearCutoff Gets or sets the specified object that is used to set the two digit year cutoff configuration option.
Public property Urn Gets the Uniform Resource Name (URN) address value that uniquely identifies the object. (Inherited from SqlSmoObject.)
Public property UserAccess Gets or sets the database user access.
Public property UserData Gets or sets user-defined data associated with the referenced object. (Inherited from SmoObjectBase.)
Public property UserDefinedAggregates Gets a collection of UserDefinedAggregate objects. Each UserDefinedAggregate object represents a user-defined aggregate defined on the database.
Public property UserDefinedDataTypes Gets a collection of UserDefinedDataType objects. Each UserDefinedDataType object represents a user-defined data type on the database.
Public property UserDefinedFunctions Gets a collection of UserDefinedFunction objects. Each UserDefinedFunction object represents a user-defined function on the database.
Public property UserDefinedTableTypes Gets a collection of UserDefinedTableType objects. Each UserDefinedTableType object represents a user-defined table type on the database.
Public property UserDefinedTypes Gets a collection of UserDefinedType objects. Each UserDefinedType object represents a user-defined type on the database.
Public property UserName Gets the database user name.
Public property Users Gets a collection of User objects. Each User object represents a user who is defined on the database.
Public property Version Gets the version of the instance of SQL Server that was used to create the database.
Public property Views Gets a collection of View objects. Each View object represents a view defined on the database.
Public property XmlSchemaCollections Gets a collection of XmlSchemaCollection objects. Each XmlSchemaCollection object represents an XML schema defined on the database.

Top

Methods

  Name Description
Protected method AddDatabaseContext Add the database context to the collection of queries identified by the queries parameter. (Inherited from SqlSmoObject.)
Public method Alter() Updates any Database object property changes on the instance of SQL Server. 
Public method Alter(TimeSpan) Updates any Database object property changes on the instance of SQL Server. 
Public method Alter(TerminationClause) Updates any Database object property changes on the instance of SQL Server. 
Protected method AlterImpl Activates the object altered event. (Inherited from SqlSmoObject.)
Protected method AlterImplWorker Calls the Alter methods. (Inherited from SqlSmoObject.)
Protected method AppendCommaText Appends text, optionally separated by a comma. (Inherited from ScriptNameObjectBase.)
Protected method AppendWithCommaText Appends text, optionally separated by a comma. (Inherited from ScriptNameObjectBase.)
Protected method AppendWithOption Appends text and option text separated from the main text with a “WITH” string and optionally separated by a comma. (Inherited from ScriptNameObjectBase.)
Protected method AutoGenerateName Generates a name based on the object Guid. (Inherited from ScriptNameObjectBase.)
Protected method BindDefaultImpl Binds the default items identified by the parameters. (Inherited from SqlSmoObject.)
Protected method BindRuleImpl Binds the rule schema to the rule and columns identified by the parameters. (Inherited from SqlSmoObject.)
Public method ChangeMirroringState Changes the mirroring configuration as specified by the options.
Public method CheckAllocations Scans all pages of the referenced database and tests pages to help ensure integrity.
Public method CheckAllocationsDataOnly Scans all pages of the referenced database and tests only the data to help ensure integrity.
Public method CheckCatalog Tests the integrity of the database catalog.
Public method CheckIdentityValues Verifies the integrity of all identity columns in tables in the database.
Protected method CheckObjectDirty Checks whether object has been modified and not persisted. (Inherited from ScriptNameObjectBase.)
Protected method CheckObjectState() Validates the state of the referenced object. (Inherited from SqlSmoObject.)
Protected method CheckObjectState(Boolean) Validates the state of the referenced object with the option to specify that an exception is thrown if the object is not yet created. (Inherited from SqlSmoObject.)
Protected method CheckObjectStateImpl Checks the state of a SqlSmoObject. (Inherited from SqlSmoObject.)
Public method Checkpoint Issues a checkpoint.
Public method CheckTables(RepairType) Tests the integrity of database pages for all tables and indexes defined on the tables of the database.
Public method CheckTables(RepairType, RepairOptions) Tests the integrity of database pages for all tables and indexes defined on the tables of the database.
Public method CheckTables(RepairType, RepairStructure) Tests the integrity of database pages for all tables and indexes defined on the tables of the database.
Public method CheckTables(RepairType, RepairOptions, RepairStructure) Tests the integrity of database pages for all tables and indexes defined on the tables of the database.
Public method CheckTablesDataOnly() Tests integrity of data in pages that store data for all tables and indexes defined on the tables of the referenced database.
Public method CheckTablesDataOnly(RepairOptions) Tests integrity of data in pages that store data for all tables and indexes defined on the tables of the referenced database, with the specified repair options.
Public method CheckTablesDataOnly(RepairStructure) Tests integrity of data in pages that store data for all tables and indexes defined on the tables of the referenced database with the specified repair structure.
Public method CheckTablesDataOnly(RepairOptions, RepairStructure) Tests integrity of data in pages that store data for all tables and indexes defined on the tables of the referenced database with the specified repair options and repair structure.
Protected method CheckTextCorectness Checks text for correctness against the parameters. (Inherited from ScriptNameObjectBase.)
Protected method CheckTextModeSupport Checks mode of support. (Inherited from ScriptNameObjectBase.)
Protected method CheckVersion100 Checks whether version of SQL Server is SQL Server 2008. (Inherited from SqlSmoObject.)
Protected method CheckVersion110() Checks whether version of SQL Server is SQL Server 2012. (Inherited from SqlSmoObject.)
Protected method CheckVersion110(String) Checks whether the version of SQL Server is SQL Server 2012 with the specified name. (Inherited from SqlSmoObject.)
Protected method CheckVersion80 Checks the validity of the object on SQL Server 2000. (Inherited from SqlSmoObject.)
Protected method CheckVersion80SP3 Checks the validity of the object on SQL Server 2000 SP3. (Inherited from SqlSmoObject.)
Protected method CheckVersion90 Check the validity of the object on SQL Server 2005. (Inherited from SqlSmoObject.)
Protected method CheckVersionBelow110 Checks whether version of SQL Server is before SQL Server 2012. (Inherited from SqlSmoObject.)
Protected method CheckVersionBelow90 Checks whether version of SQL Server is before SQL Server 2005. (Inherited from SqlSmoObject.)
Protected method CleanObject Cleans the referenced object. (Inherited from ScriptNameObjectBase.)
Public method Create() Creates a database on the instance of SQL Server as defined by the Database object.
Public method Create(Boolean) Creates a database on the instance of SQL Server as defined by the Database object.
Protected method CreateImpl Creates an object with scripting options. (Inherited from SqlSmoObject.)
Public method Deny(DatabasePermissionSet, String) Denies the specified set of permissions for the specified grantee on the database.
Public method Deny(DatabasePermissionSet, array<String[]) Denies the specified set of permissions for the specified grantees on the database.
Public method Deny(DatabasePermissionSet, String, Boolean) Denies the specified set of permissions for the specified grantee and other users who the grantee granted the specified set of permissions on the database.
Public method Deny(DatabasePermissionSet, array<String[], Boolean) Denies the specified set of permissions for the specified grantees and other users who the grantee granted the specified set of permissions on the database.
Public method DisableAllPlanGuides Disables all Plan Guides in a database.
Public method Discover Discovers a list of type Object. (Inherited from SqlSmoObject.)
Public method Drop Drops the database.
Public method DropAllPlanGuides Drops all Plan Guides in a database.
Public method DropBackupHistory Drops the backup history for the database.
Protected method DropImpl Drops a SqlSmoObject. (Inherited from SqlSmoObject.)
Protected method DropImplWorker Calls the drop methods. (Inherited from SqlSmoObject.)
Public method EnableAllPlanGuides Enables all Plan Guides in a database.
Public method EnumBackupSetFiles() Returns a DataTable listing files contained in a backup set.
Public method EnumBackupSetFiles(Int32) Returns a Data table that lists the files in a backup set
Public method EnumBackupSets Returns a DataTable listing the backup sets associated with a database.
Public method EnumCandidateKeys Enumerates a list of all candidate primary keys in the database, which can be referenced by a foreign key.
Public method EnumDatabasePermissions() Enumerates a list of all permissions in the database.
Public method EnumDatabasePermissions(String) Enumerates a list of permissions in the database for the specified user.
Public method EnumDatabasePermissions(DatabasePermissionSet) Enumerates a list of permissions in the database for the specified permission set.
Public method EnumDatabasePermissions(String, DatabasePermissionSet) Enumerates a list of permissions in the database for the specified user and a specified permission set.
Public method EnumLocks() Enumerates a list of all current locks held on the database.
Public method EnumLocks(Int32) Enumerates a list of current locks held on the database for a specified system process ID.
Public method EnumLoginMappings Enumerates a list of SQL Server logins for all the users in the database.
Public method EnumMatchingSPs(String) Enumerates a list of stored procedures that contain the specified string in the definition.
Public method EnumMatchingSPs(String, Boolean) Enumerates a list of stored procedures that contain the specified string in the definition.
Public method EnumObjectPermissions() Enumerates a list of permissions for objects in the database.
Public method EnumObjectPermissions(String) Enumerates a list of permissions for objects in the database that belong to the specified user.
Public method EnumObjectPermissions(ObjectPermissionSet) Enumerates a list of permissions for objects in the database limited to the specified permission set.
Public method EnumObjectPermissions(String, ObjectPermissionSet) Enumerates a list of permissions for objects in the database that belong to the specified user and limited to the specified permission set.
Public method EnumObjects() Enumerates a list of objects in the database.
Public method EnumObjects(DatabaseObjectTypes) Enumerates a list of objects in the database.
Public method EnumObjects(DatabaseObjectTypes, SortOrder) Enumerates a list of objects in the database.
Public method EnumTransactions() Enumerates a list of open transactions on the database.
Public method EnumTransactions(TransactionTypes) Enumerates a list of open transactions of a specified type on the database.
Public method EnumWindowsGroups() Enumerates a list of Windows groups.
Public method EnumWindowsGroups(String) Enumerates a list of Windows groups for a specified group.
Public method Equals (Inherited from Object.)
Public method ExecuteNonQuery(StringCollection) Executes a batch in the context of the database where there are no results returned.
Public method ExecuteNonQuery(String) Executes a statement in the context of the database where there are no results returned.
Public method ExecuteNonQuery(StringCollection, ExecutionTypes) Runs a collection of batches in the context of the database where there are no results returned for the specified execution type only.
Public method ExecuteNonQuery(String, ExecutionTypes) Executes a batch in the context of the database where there are no results returned for the specified execution type only.
Protected method ExecuteNonQuery(StringCollection, Boolean) Executes a batch of statements that does not return a result set. (Inherited from SqlSmoObject.)
Protected method ExecuteRenameQuery Executes the rename query for the object. (Inherited from NamedSmoObject.)
Public method ExecuteWithResults(StringCollection) Executes a batch in the context of the database where there are results returned.
Public method ExecuteWithResults(String) Executes a collection of batches in the context of the database where there are results returned.
Protected method Finalize (Inherited from Object.)
Protected method ForceTextModeOnTextBody Enforces text mode on the text body. (Inherited from ScriptNameObjectBase.)
Protected method FormatSqlVariant Formats an object as SqlVariant type. (Inherited from SqlSmoObject.)
Protected method GenerateAlterEvent() Generates the alter event with the specified value. (Inherited from SqlSmoObject.)
Protected method GenerateAlterEvent(Urn, Object) Generates alter event with the specified URN and inner object value. (Inherited from SqlSmoObject.)
Protected method GetBraketNameForText Gets the bracket name for the text. (Inherited from ScriptNameObjectBase.)
Protected method GetContextDB Gets the context database that is associated with this object. (Inherited from SqlSmoObject.)
Protected method GetDBName Gets the database name that is associated with the object. (Inherited from SqlSmoObject.)
Protected method GetFragOptionString Gets a FragmentationOption object as a string value. (Inherited from SqlSmoObject.)
Public method GetHashCode (Inherited from Object.)
Protected method GetIsSystemNamed Gets a Boolean value that specifies whether the system is named. (Inherited from ScriptNameObjectBase.)
Protected method GetIsTextDirty Determines whether the text value is consistent with stored value. (Inherited from ScriptNameObjectBase.)
Protected method GetPropValue Gets a property value of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Protected method GetPropValueOptional Gets a property value of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Protected method GetPropValueOptionalAllowNull Gets a property value of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Protected method GetRealValue Gets a property value of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Protected method GetServerName Gets the name of the instance of SQL Server with which the object is associated. (Inherited from SqlSmoObject.)
Protected method GetServerObject Gets the server of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Protected method GetSqlServerVersionName Gets the version name of the instance of SQL Server with which the object is associated. (Inherited from SqlSmoObject.)
Protected method GetTextBody() Returns the text body. (Inherited from ScriptNameObjectBase.)
Protected method GetTextBody(Boolean) Returns the text body. (Inherited from ScriptNameObjectBase.)
Protected method GetTextHeader Returns the text header. (Inherited from ScriptNameObjectBase.)
Protected method GetTextMode Determines whether the script name is using text mode. (Inherited from ScriptNameObjectBase.)
Protected method GetTextProperty Gets the text of the object, if not available, throw appropriate exception based on the state of the object. (Inherited from ScriptNameObjectBase.)
Public method GetTransactionCount() Gets the number of open transactions on the database.
Public method GetTransactionCount(TransactionTypes) Gets the number of open transactions of a specified type on the database.
Public method GetType (Inherited from Object.)
Protected method GetUrnRecursive(StringBuilder) Assigns an Urn object of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Protected method GetUrnRecursive(StringBuilder, UrnIdOption) Assigns an Urn object of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Public method Grant(DatabasePermissionSet, String) Grants the specified set of permissions to the specified grantee on the database.
Public method Grant(DatabasePermissionSet, array<String[]) Grants the specified set of permissions to the specified grantees on the database.
Public method Grant(DatabasePermissionSet, String, Boolean) Grants access to the specified permission to the grantee and the ability to grant access to other users on the database.
Public method Grant(DatabasePermissionSet, array<String[], Boolean) Grants access to the specified permission to the grantees and the ability to grant access to other users on the database.
Public method Grant(DatabasePermissionSet, String, Boolean, String) Grants the specified set of permissions to the grantee and the ability to grant the set of permissions to other users on the database under an assumed role.
Public method Grant(DatabasePermissionSet, array<String[], Boolean, String) Grants the specified set of permissions to the grantees and the ability to grant the set of permissions to other users on the database under an assumed role.
Protected method ImplInitialize Initializes the fields of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Public method Initialize() Initializes the object and forces the properties be loaded. (Inherited from SqlSmoObject.)
Public method Initialize(Boolean) Initializes the object and forces the properties be loaded. (Inherited from SqlSmoObject.)
Public method IsMember Determines whether the specified group or role belongs to the database.
Protected method IsObjectDirty Determines whether the referenced object is consistent with the stored object. (Inherited from ScriptNameObjectBase.)
Protected method IsObjectInitialized Verifies whether the object has been initialized. (Inherited from SqlSmoObject.)
Protected method IsObjectInSpace Verifies whether the object is isolated or connected to the instance of SQL Server. (Inherited from SqlSmoObject.)
Protected method IsVersion80SP3 Determines whether the version of SQL Server is SQL Server 2000 with SP3. (Inherited from SqlSmoObject.)
Protected method IsVersion90AndAbove Determines whether the version of SQL Server is SQL Server 2005 or later. (Inherited from SqlSmoObject.)
Protected method MarkDropped Sets the SqlSmoState to dropped. (Inherited from SqlSmoObject.)
Protected method MarkForDropImpl Sets the SqlSmoState for drop operation. (Inherited from SqlSmoObject.)
Protected method MemberwiseClone (Inherited from Object.)
Protected method PostAlter The method that is activated after the SqlSmoObject is altered. (Inherited from SqlSmoObject.)
Protected method PostCreate The method that is activated after the SqlSmoObject is created. (Inherited from SqlSmoObject.)
Protected method PostDrop The method that is activated after the SqlSmoObject is dropped. (Inherited from SqlSmoObject.)
Public method PrefetchObjects() Prefetches database objects.
Public method PrefetchObjects(Type) Prefetches database objects of a specified type.
Public method PrefetchObjects(Type, ScriptingOptions) Prefetches database objects of a specified type with scripting options.
Public method RecalculateSpaceUsage Recalculates space usage.
Public method Refresh Updates the Database object. (Overrides ScriptNameObjectBase.Refresh().)
Public method RemoveFullTextCatalogs Removes full-text catalogs from the database.
Public method Rename Renames the database.
Protected method RenameImpl This method supports the SMO infrastructure and is not intended to be used directly from your code. (Inherited from NamedSmoObject.)
Protected method RenameImplWorker Identified for informational purposes only. Not supported. Future compatibility is not guaranteed. (Inherited from NamedSmoObject.)
Public method Revoke(DatabasePermissionSet, String) Revokes a previously granted set of permissions from a grantee on the database.
Public method Revoke(DatabasePermissionSet, array<String[]) Revokes a previously granted set of permissions from a list of grantees on the database.
Public method Revoke(DatabasePermissionSet, String, Boolean, Boolean) Revokes previously granted permissions from a grantee on the database and any other users to whom the grantee has granted the specified set of permissions. The grantee is also given the ability to revoke the specified set of permissions from other users under an assumed role.
Public method Revoke(DatabasePermissionSet, array<String[], Boolean, Boolean) Revokes previously granted permissions from grantees on the database and any other users to whom the grantees have granted the specified set of permissions. The grantees are also given the ability to revoke the specified set of permissions from other users under an assumed role.
Public method Revoke(DatabasePermissionSet, String, Boolean, Boolean, String) Revokes previously granted permissions from a grantee on the database and any other users to whom the grantee has granted the specified set of permissions. The grantee is also given the ability to revoke the specified set of permissions from other users under an assumed role.
Public method Revoke(DatabasePermissionSet, array<String[], Boolean, Boolean, String) Revokes previously granted permissions from grantees on the database and any other users to whom the grantees have granted the specified set of permissions. The grantees are also given the ability to revoke the specified set of permissions from other users under an assumed role.
Public method Script() Generates a Transact-SQL script that can be used to re-create the database.
Public method Script(ScriptingOptions) Generates a Transact-SQL script that can be used to re-create the database as specified by the script options.
Protected method ScriptImpl() Gets a collection of scripts of the SqlSmoObject. (Inherited from SqlSmoObject.)
Protected method ScriptImpl(ScriptingOptions) Gets a collection of scripts of the SqlSmoObject. (Inherited from SqlSmoObject.)
Protected method SetCollectionTextMode Sets the collection text mode. (Inherited from ScriptNameObjectBase.)
Public method SetDefaultFileGroup Sets the default file group for the database.
Public method SetDefaultFileStreamFileGroup Sets the default filestream group.
Public method SetDefaultFullTextCatalog Sets the default full-text catalog for the database.
Protected method SetIsSystemNamed Sets a Boolean value that specifies whether the system is named. (Inherited from ScriptNameObjectBase.)
Public method SetOffline Sets the database offline.
Public method SetOnline Sets the database online.
Public method SetOwner(String) Sets the database owner.
Public method SetOwner(String, Boolean) Sets the database owner.
Protected method SetParentImpl Sets the parent of the SqlSmoObject to the newParent parameter. (Inherited from SqlSmoObject.)
Protected method SetSchemaOwned Sets the schema owned value. (Inherited from NamedSmoObject.)
Public method SetSnapshotIsolation Sets the snapshot isolation level.
Protected method SetTextBody Specifies the text body. (Inherited from ScriptNameObjectBase.)
Protected method SetTextHeader Specifies the text header. (Inherited from ScriptNameObjectBase.)
Protected method SetTextMode Specifies the text mode. (Inherited from ScriptNameObjectBase.)
Public method Shrink Shrinks the database.
Protected method SwitchTextMode Switches the text mode. (Inherited from ScriptNameObjectBase.)
Protected method ThrowIfTextIsDirtyForAlter Throws an exception of text has been modified and not persisted. (Inherited from ScriptNameObjectBase.)
Public method ToString Returns a String that represents the referenced object. (Inherited from SqlSmoObject.)
Protected method TouchImpl Not implemented. (Inherited from SqlSmoObject.)
Public method TruncateLog Truncates the database log.
Protected method UnbindDefaultImpl Unbinds the default columns of the SqlSmoObject. (Inherited from SqlSmoObject.)
Protected method UnbindRuleImpl Unbinds rules of the SqlSmoObject. (Inherited from SqlSmoObject.)
Public method UpdateIndexStatistics Updates index statistics.
Public method Validate Validates the state of an object. (Inherited from SmoObjectBase.)
Public method ValidateAllPlanGuides() Verifies the validity of the execution plans associated with the database.
Public method ValidateAllPlanGuides(DataTable%) Verifies the validity of the execution plans associated with the database and returns validation report.

Top

Events

  Name Description
Public event PropertyChanged Represents the event that occurs when a property is changed. (Inherited from SqlSmoObject.)
Public event PropertyMetadataChanged Represents the event that occurs when property metadata changes. (Inherited from SqlSmoObject.)

Top

Fields

  Name Description
Protected field m_ExtendedProperties Represents a property that is defined to extend the properties provided by a SqlSmoObject. (Inherited from SqlSmoObject.)
Protected field singletonParent Represents the singleton parent. (Inherited from SqlSmoObject.)

Top

Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate method IAlienObject.Discover Discovers any dependencies. Do not reference this member directly in your code. It supports the SQL Server infrastructure. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate method IAlienObject.GetDomainRoot Returns the root of the domain. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate method IAlienObject.GetParent Gets the parent of this object. Do not reference this member directly in your code. It supports the SQL Server infrastructure. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate method IAlienObject.GetPropertyType Gets the type of the specified property. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate method IAlienObject.GetPropertyValue Gets the value of the specified property. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate method IAlienObject.GetUrn Gets the Unified Resource Name (URN) of the object. Do not reference this member directly in your code. It supports the SQL Server infrastructure. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate method IAlienObject.Resolve Gets the instance that contains the information about the object from the Unified Resource Name (URN) of the object. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate method IAlienObject.SetObjectState Sets the object state to the specified SfcObjectState value. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate method IAlienObject.SetPropertyValue Sets the property value. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate method ISfcPropertyProvider.GetPropertySet Gets the interface reference to the set of properties of this object. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate property ISfcSupportsDesignMode.IsDesignMode Gets a value that indicates whether the object supports design mode. Identified for informational purposes only. Not supported. Future compatibility is not guaranteed.

Top

Remarks

The Database class represents databases, either system or user-defined, on the instance of SQL Server. The Server class is the parent of the Database class.

By using the Database class, you can do the following:

  • Create a new database or drop an existing database.

  • Register the database in the Active Directory service.

  • Reference database objects in collections, such as tables, users, and triggers.

  • Set up database mirroring.

  • Create a master database key.

  • Set up a full-text search catalog.

  • Check data, allocations, catalogs, and tables.

  • Issue a checkpoint.

  • Grant, revoke, and deny permissions to users on the database.

  • Run Transact-SQL statements.

  • Enumerate database information, such as locks or object permissions.

  • Remove the backup history.

  • Monitor the number of transactions.

  • Set the database offline or online.

  • Change the owner of the database.

  • Update statistics.

  • Shrink the database.

  • Truncate the log.

  • Script the database.

To get Database object properties, a login must be a member of the public fixed server role and the user mapped to this login in the database must be a member of the public database role.

To set Database object properties and run the Alter method, users must have ALTER permission on the database, or be a member of the db_owner fixed database role.

To create a database, users must have CREATE DATABASE, CREATE ANY DATABASE, or ALTER ANY DATABASE permission on the parent server.

To drop a database, users must have CONTROL permission on the database, or be a member of the db_owner fixed database role.

To grant, revoke, or deny other users permission on the database, users must have CONTROL permission on the database or be a member of the db_owner fixed database role.

Thread Safety

Any public static (Shared in Microsoft Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.

Examples

VB

'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Define a Database object variable by supplying the server and the database name arguments in the constructor.
Dim db As Database
db = New Database(srv, "Test_SMO_Database")
'Create the database on the instance of SQL Server.
db.Create()
'Reference the database and display the date when it was created.
db = srv.Databases("Test_SMO_Database")
Console.WriteLine(db.CreateDate)
'Remove the database.
db.Drop()

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")
$db = New-Object Microsoft.SqlServer.Management.Smo.Database($srv, "Test_SMO_Database")
$db.Create()
Write-Host $db.CreateDate
$db.Drop()

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Microsoft.SqlServer.Management.Smo Namespace

Other Resources

Working with Database Objects

Creating, Altering, and Removing Databases

CREATE DATABASE (Transact-SQL)