Export (0) Print
Expand All

Database Class

The Database object represents a SQL Server database.

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

[EvaluationModeAttribute(AutomatedPolicyEvaluationMode.CheckOnSchedule)]
[PhysicalFacetAttribute]
public sealed class Database : ScriptNameObjectBase, 
	ICreatable, IAlterable, IDroppable, IRenamable, IExtendedProperties, 
	IScriptable, IDatabaseOptions, IDmfFacet, ISfcSupportsDesignMode

The Database type exposes the following members.

  NameDescription
Public methodDatabase()Initializes a new instance of the Database class.
Public methodDatabase(Server, String)Initializes a new instance of the Database class on the specified server and with the specified name.
Top

  NameDescription
Public propertyActiveConnectionsGets the number of active connections to the database.
Public propertyActiveDirectoryGets the information about the Active Directory settings for the database.
Public propertyAnsiNullDefaultGets or sets AnsiNullDefault Property.
Public propertyAnsiNullsEnabledGets or sets the Boolean ANSI_NULLS_ENABLED property value.
Public propertyAnsiPaddingEnabledGets or sets the ANSI_PADDING_ENABLED database option is enabled.
Public propertyAnsiWarningsEnabledGets or sets the Boolean ANSI_WARNING_ENABLED property value.
Public propertyApplicationRolesRepresents a collection of ApplicationRole objects. Each ApplicationRole object represents an application role defined on the database.
Public propertyArithmeticAbortEnabledGets or sets the ARITHMETICABORT property value.
Public propertyAssembliesRepresents a collection of SqlAssembly objects. Each SqlAssembly object represents an assembly defined on the database.
Public propertyAsymmetricKeysRepresents a collection of AsymmetricKey objects. Each AsymmetricKey object represents an asymmetric key defined on the database.
Public propertyAutoCloseGets or sets the AUTOCLOSE database option is set.
Public propertyAutoCreateStatisticsEnabledGets a Boolean property value that specifies whether statistics are automatically created for the database.
Public propertyAutoShrinkGets or sets the AUTO_SHRINK database option.
Public propertyAutoUpdateStatisticsAsyncGets or sets a property value that specifies whether the AUTOUPDATESTATISTICSASYNC database option is active.
Public propertyAutoUpdateStatisticsEnabledGets a Boolean property value that specifies whether statistics are automatically updated for the database.
Public propertyBrokerEnabledGets or sets a property value that specifies whether the Service Broker service is enabled.
Public propertyCaseSensitiveGets a Boolean property value that specifies whether uppercase letters and lowercase letters are evaluated as equal.
Public propertyCertificatesRepresents a collection of Certificate objects. Each Certificate object represents a certificate defined on the database.
Public propertyChangeTrackingAutoCleanUpGets or sets a Boolean property value that specifies whether the CHANGE_TRACKING_AUTO_CLEANUP OPTION is enabled.
Public propertyChangeTrackingEnabledGets or sets a property value that specifies whether the CHANGE_TRACKING_VALUE option is enabled
Public propertyChangeTrackingRetentionPeriodGets or sets the CHANGE_TRACKING_RETENTION_PERIOD value.
Public propertyChangeTrackingRetentionPeriodUnitsGets or sets the unit type for a retention period value.
Public propertyCloseCursorsOnCommitEnabledGets or sets a value that specifies whether the CURSOR_CLOSE_ON_COMMIT database option is active.
Public propertyCollationGets or sets the default collation used by the database.
Public propertyCompatibilityLevelGets or sets the compatibility level for the database.
Public propertyConcatenateNullYieldsNullGets or sets a property value that specifies whether the CONCAT_NULL_YIELDS_NULL database option is active.
Public propertyCreateDateGets the date that the database was created.
Public propertyDatabaseAuditSpecificationsRepresents a collection of DatabaseAuditSpecification objects. Each DatabaseAuditSpecification object represents an database audit specification defined on the server.
Public propertyDatabaseEncryptionKeyGets a DataBaseEncryptionKey datatype.
Public propertyDatabaseGuidGets the Guid value that uniquely identifies the database.
Public propertyDatabaseOptionsGets the DatabaseOptions object that contains configuration options for the database.
Public propertyDatabaseOwnershipChainingGets or sets a property value that specifies whether the database ownership chaining is active.
Public propertyDatabaseSnapshotBaseNameGets the name of the snapshot base for the database.
Public propertyDataSpaceUsageGets the space used by the data in the database.
Public propertyDateCorrelationOptimizationGets or sets a property value that specifies whether the date correlation optimization is active. For more information about date correlation optimization, see Setting Database Options.
Public propertyDboLoginGets the Boolean value that specifies whether the current user is logged on as the database owner (DBO).
Public propertyDefaultFileGroupGets the default file group used by the database.
Public propertyDefaultFileStreamFileGroupGets a DefaultFileStreamFileGroup datatype
Public propertyDefaultFullTextCatalogGets the default full-text catalog used by the database.
Public propertyDefaultsRepresents a collection of Default objects. Each Default object represents a default defined on the database.
Public propertyDefaultSchemaGets the default schema of the user.
Public propertyEncryptionEnabledGets or sets the ENCRYPTIONENABLED property of a database.
Public propertyEventsGets the events associated with the database.
Protected propertyExecuteForScalarGets or sets the Boolean property value that specifies whether the object is set to the execute for scalar option. (Inherited from SqlSmoObject.)
Public propertyExtendedPropertiesGets the extended properties of the database.
Public propertyExtendedStoredProceduresRepresents a collection of ExtendedStoredProcedure objects. Each ExtendedStoredProcedure object represents an extended stored procedure defined on the database.
Public propertyFileGroupsRepresents a collection of FileGroup objects. Each FileGroup object represents a filegroup defined on the database.
Public propertyFullTextCatalogsRepresents a collection of FullTextCatalog objects. Each FullTextCatalog object represents a full-text catalog defined on the database.
Public propertyFullTextStopListsRepresents a collection of FullTextStopList objects. Each FullTextStopList object represents a full text stop list defined on the server.
Public propertyHonorBrokerPriorityGets or sets the Boolean value that specifies whether the priority specified by the broker is acknowledged or not.
Public propertyIDGets the database ID value that uniquely identifies the database.
Public propertyIndexSpaceUsageGets the space used by the indexes in the database.
Public propertyIsAccessibleGets a Boolean property value that specifies whether the database can be accessed.
Public propertyIsDatabaseSnapshotGets a Boolean property value that specifies whether the database is a snapshot database.
Public propertyIsDatabaseSnapshotBaseGets a Boolean property value that specifies whether the database is the base database for a snapshot database.
Public propertyIsDbAccessAdminGets a Boolean property value that specifies whether the current user is a member of the DbAccessAdmin database role.
Public propertyIsDbBackupOperatorGets a Boolean property value that specifies whether the current user is a member of the DbBackupOperator database role.
Public propertyIsDbDatareaderGets a Boolean property value that specifies whether the current user is a member of the DbDatareader database role.
Public propertyIsDbDatawriterGets a Boolean property value that specifies whether the current user is a member of the DbDatawriter database role.
Public propertyIsDbDdlAdminGets a Boolean property value that specifies whether the current user is a member of the DbDdlAdmin database role.
Public propertyIsDbDenyDatareaderGets a Boolean property value that specifies whether the current user is a member of the DbDenyDatareader database role.
Public propertyIsDbDenyDatawriterGets a Boolean property value that specifies whether the current member is a member of the DbDenyDatawriter database.
Public propertyIsDbManagerGets a Boolean value that specifies whether the current login is a database manager in SQL Azure.
Public propertyIsDbOwnerGets a Boolean property value that specifies whether the current user is a member of the DbOwner database role.
Public propertyIsDbSecurityAdminGets a Boolean property value that specifies whether the current user is a member of the DbSecurityAdmin database role.
Public propertyIsFullTextEnabledGets the Boolean value that specifies whether the database is enabled for full-text search.
Public propertyIsLoginManagerGets a Boolean value that specifies whether the current login is a login manager in SQL Azure.
Public propertyIsMailHostGets the Boolean value that specifies whether the database is configured as a mail host.
Public propertyIsManagementDataWarehouseGets the Boolean value that specifies whether the database is a management data warehouse.
Public propertyIsMirroringEnabledGets the Boolean value that specifies whether mirroring is enabled on the database.
Public propertyIsParameterizationForcedGets or sets a property value that specifies whether parameterization is forced on the database.
Public propertyIsReadCommittedSnapshotOnGets the Boolean value that specifies whether transactions with the read committed isolation level use row versioning.
Public propertyIsSystemObjectGets the Boolean value that specifies whether the database is a system object or a user-defined database.
Protected propertyIsTouchedGets the Boolean property value that specifies whether the object properties have been updated but not yet persisted on the server. (Inherited from SqlSmoObject.)
Public propertyIsUpdateableGets the Boolean value that specifies whether the database can be updated.
Public propertyIsVarDecimalStorageFormatEnabledGets or sets a property value that specifies whether VarDecimal storage is enabled.
Public propertyLastBackupDateGets the date and time when the database was last backed up.
Public propertyLastDifferentialBackupDateGets the date and time when the last differential backup was performed.
Public propertyLastLogBackupDateGets the date and time when the transaction log was last backed up.
Public propertyLocalCursorsDefaultGets the Boolean value that specifies whether the local server cursors are used by default.
Public propertyLogFilesRepresents a collection of LogFile objects. Each LogFile object represents a log file defined on the database.
Public propertyLogReuseWaitStatusGets the type of operation on which the reuse of transaction log space is waiting.
Public propertyMasterKeyGets the master key that is used to encrypt the private keys of certificates.
Public propertyMirroringFailoverLogSequenceNumberGets the log sequence number at last failover.
Public propertyMirroringIDGets the ID value that uniquely identifies the mirroring partnership.
Public propertyMirroringPartnerGets or sets the address of the Database Engine instance that is the partner server for database mirroring.
Public propertyMirroringPartnerInstanceGets the instance of SQL Server on which the mirroring partner is configured.
Public propertyMirroringRedoQueueMaxSizeGets or sets the maximum size of the redo queue of the mirror server instance in KB.
Public propertyMirroringRoleSequenceGets the role sequence number for primary/backup roles played by the mirroring partners.
Public propertyMirroringSafetyLevelGets or sets the mirroring safety level.
Public propertyMirroringSafetySequenceGets the role sequence number for safety levels for the mirroring partners.
Public propertyMirroringStatusGets the status of the database and the database mirroring session.
Public propertyMirroringTimeoutGets 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 propertyMirroringWitnessGets or sets the name of the Database Engine instance of the database mirroring witness server.
Public propertyMirroringWitnessStatusGets the status of the mirroring witness server.
Public propertyNameGets or sets the name of the database. (Overrides NamedSmoObject.Name.)
Public propertyNumericRoundAbortEnabledGets or sets a Boolean property value that specifies whether the NUMERIC_ROUNDABORT database option is active.
Protected propertyObjectInSpaceGets 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 propertyOwnerGets the database principal that is the owner of the database.
Public propertyPageVerifySpecifies the type of page integrity check that SQL Server performs when reading database pages.
Public propertyParentGets the Server object that is the parent of the Database object.
Public propertyPartitionFunctionsRepresents a collection of PartitionFunction objects. Each PartitionFunction object represents a partition function defined on the database.
Public propertyPartitionSchemesRepresents a collection of PartitionScheme objects. Each PartitionScheme object represents a partition scheme defined on the database.
Public propertyPlanGuidesGets Plan Guides associated with a database.
Public propertyPrimaryFilePathGets the operating system directory that contains the primary file for the database.
Public propertyPropertiesGets a collection of Property objects that represent the object properties. (Inherited from SqlSmoObject.)
Public propertyQuotedIdentifiersEnabledGets or sets a Boolean property 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 propertyReadOnlyGets or sets the Boolean property value that specifies whether the database is read-only.
Public propertyRecoveryForkGuidGets the GUID value that specifies the recovery fork on which the database is currently active.
Public propertyRecoveryModelGets or sets the recovery model for the database.
Public propertyRecursiveTriggersEnabledGets or sets the Boolean value that specifies whether recursive triggers are enabled on the database.
Public propertyReplicationOptionsGets the active replication settings for a database,
Public propertyRolesRepresents a collection of DatabaseRole objects. Each DatabaseRole object represents a role defined on the database.
Public propertyRulesRepresents a collection of Rule objects. Each Rule object represents a rule defined on the database.
Protected propertyScalarResultGets the scalar result for the referenced object. (Inherited from SqlSmoObject.)
Public propertySchemasRepresents a collection of Schema objects. Each Schema object represents a schema defined on the database.
Public propertyServiceBrokerGets the ServiceBroker object that represents the Service Broker.
Public propertyServiceBrokerGuidGets the Guid object that uniquely identifies the instance of Service Broker.
Public propertySizeGets the size of the database in MB.
Public propertySnapshotIsolationStateGets the snapshot isolation state for the database.
Public propertySpaceAvailableGets the available space in the database in KB.
Public propertyStateGets the state of the referenced object. (Inherited from SmoObjectBase.)
Public propertyStatusGets the database status.
Public propertyStoredProceduresRepresents a collection of StoredProcedure objects. Each StoredProcedure object represents a stored procedure defined on the database.
Public propertySymmetricKeysRepresents a collection of SymmetricKey objects. Each SymmetricKey object represents a symmetric key defined on the database.
Public propertySynonymsRepresents a collection of Synonym objects. Each Synonym object represents a synonym defined on the database.
Public propertyTablesRepresents a collection of Table objects. Each Table object represents a table defined on the database.
Public propertyTriggersRepresents a collection of DatabaseDdlTrigger objects. Each DatabaseDdlTrigger object represents a trigger defined on the database.
Public propertyTrustworthyThe TRUSTWORTHY database property is used to indicate whether the instance of SQL Server 2005 trusts the database and the contents within it
Public propertyUrnGets the Uniform Resource Name (URN) address value that uniquely identifies the object. (Inherited from SqlSmoObject.)
Public propertyUserAccessGets or sets the database user access.
Public propertyUserDataGets or sets user-defined data associated with the referenced object. (Inherited from SmoObjectBase.)
Public propertyUserDefinedAggregatesRepresents a collection of UserDefinedAggregate objects. Each UserDefinedAggregate object represents a user-defined aggregate defined on the database.
Public propertyUserDefinedDataTypesRepresents a collection of UserDefinedDataType objects. Each UserDefinedDataType object represents a user-defined data type on the database.
Public propertyUserDefinedFunctionsRepresents a collection of UserDefinedFunction objects. Each UserDefinedFunction object represents a user-defined function on the database.
Public propertyUserDefinedTableTypesRepresents a collection of UserDefinedTableType objects. Each UserDefinedTableType object represents a user-defined table type on the database.
Public propertyUserDefinedTypesRepresents a collection of UserDefinedType objects. Each UserDefinedType object represents a user-defined type on the database.
Public propertyUserNameGets or sets the database user name.
Public propertyUsersRepresents a collection of User objects. Each User object represents a user who is defined on the database.
Public propertyVersionGets the version of the instance of SQL Server that was used to create the database.
Public propertyViewsRepresents a collection of View objects. Each View object represents a view defined on the database.
Public propertyXmlSchemaCollectionsRepresents a collection of XmlSchemaCollection objects. Each XmlSchemaCollection object represents an XML schema defined on the database.
Top

  NameDescription
Protected methodAddDatabaseContext(StringCollection)Add the database context to the collection of queries identified by the queries parameter. (Inherited from SqlSmoObject.)
Protected methodAddDatabaseContext(StringCollection, ScriptingOptions)Add the database context to the collection of queries identified by the queries parameter, and using the specified scripting options. (Inherited from SqlSmoObject.)
Public methodAlter()Updates any Database object property changes on the instance of SQL Server. 
Public methodAlter(TimeSpan)Updates any Database object property changes on the instance of SQL Server. 
Public methodAlter(TerminationClause)Updates any Database object property changes on the instance of SQL Server. 
Protected methodAlterImplActivates the object altered event. (Inherited from SqlSmoObject.)
Protected methodAlterImplFinishMethod called when object altered event finishes. (Inherited from SqlSmoObject.)
Protected methodAlterImplInitMethod called when object-altered event is intialized. (Inherited from SqlSmoObject.)
Protected methodAlterImplWorkerCalls the Alter methods. (Inherited from SqlSmoObject.)
Protected methodAppendCommaTextAppends text, optionally separated by a comma. (Inherited from ScriptNameObjectBase.)
Protected methodAppendWithCommaTextAppends text, optionally separated by a comma. (Inherited from ScriptNameObjectBase.)
Protected methodAppendWithOptionAppends text and option text separated from the main text with a “WITH” string and optionally separated by a comma. (Inherited from ScriptNameObjectBase.)
Protected methodAutoGenerateNameGenerates a name based on the object Guid. (Inherited from ScriptNameObjectBase.)
Protected methodBindDefaultImplBinds the default items identified by the parameters. (Inherited from SqlSmoObject.)
Protected methodBindRuleImplBinds the rule schema to the rule and columns identified by the parameters. (Inherited from SqlSmoObject.)
Public methodChangeMirroringStateChanges the mirroring configuration as specified by the options.
Public methodCheckAllocationsScans all pages of the referenced database and tests pages to help ensure integrity.
Public methodCheckAllocationsDataOnlyScans all pages of the referenced database and tests only the data to help ensure integrity.
Public methodCheckCatalogTests the integrity of the database catalog.
Protected methodCheckCollationChecks the order of the scripting options by the collation method identified by the collationName parameter. (Inherited from SqlSmoObject.)
Public methodCheckIdentityValuesVerifies the integrity of all identity columns in tables in the database.
Protected methodCheckObjectDirtyChecks whether object has been modified and not persisted. (Inherited from ScriptNameObjectBase.)
Protected methodCheckObjectState()Validates the state of the referenced object. (Inherited from SqlSmoObject.)
Protected methodCheckObjectState(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 methodCheckObjectStateImplChecks the state of a SqlSmoObject. (Inherited from SqlSmoObject.)
Public methodCheckpointIssues a checkpoint.
Public methodCheckTables(RepairType)Tests the integrity of database pages for all tables and indexes defined on the tables of the database.
Public methodCheckTables(RepairType, RepairOptions)Tests the integrity of database pages for all tables and indexes defined on the tables of the database.
Public methodCheckTables(RepairType, RepairStructure)Tests the integrity of database pages for all tables and indexes defined on the tables of the database.
Public methodCheckTables(RepairType, RepairOptions, RepairStructure)Tests the integrity of database pages for all tables and indexes defined on the tables of the database.
Public methodCheckTablesDataOnly()Tests integrity of data in pages that store data for all tables and indexes defined on the tables of the referenced database.
Public methodCheckTablesDataOnly(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 methodCheckTablesDataOnly(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 methodCheckTablesDataOnly(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 methodCheckTextCorectnessChecks text for correctness against the parameters. (Inherited from ScriptNameObjectBase.)
Protected methodCheckTextModeSupportChecks mode of support. (Inherited from ScriptNameObjectBase.)
Protected methodCheckVersion100Checks whether version of SQL Server is SQL Server 2008. (Inherited from SqlSmoObject.)
Protected methodCheckVersion80Checks the validity of the object on SQL Server 2000. (Inherited from SqlSmoObject.)
Protected methodCheckVersion80SP3Checks the validity of the object on SQL Server 2000 SP3. (Inherited from SqlSmoObject.)
Protected methodCheckVersion90Check the validity of the object on SQL Server 2005. (Inherited from SqlSmoObject.)
Protected methodCheckVersionBelow90Checks whether version of SQL Server is before SQL Server 2005. (Inherited from SqlSmoObject.)
Protected methodCleanObjectCleans the referenced object. (Inherited from ScriptNameObjectBase.)
Public methodCreate()Creates a database on the instance of SQL Server as defined by the Database object.
Public methodCreate(Boolean)Creates a database on the instance of SQL Server as defined by the Database object.
Protected methodCreateImplCreates an object with scripting options. (Inherited from SqlSmoObject.)
Protected methodCreateImplFinishMethod called when the create event finishes. (Inherited from SqlSmoObject.)
Protected methodCreateImplInitMethod called when the create event initializes. (Inherited from SqlSmoObject.)
Public methodDeny(DatabasePermissionSet, String)Denies the specified set of permissions for the specified grantee on the database.
Public methodDeny(DatabasePermissionSet, String[])Denies the specified set of permissions for the specified grantees on the database.
Public methodDeny(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 methodDeny(DatabasePermissionSet, 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 methodDisableAllPlanGuidesDisables all Plan Guides in a database.
Public methodDiscoverDiscovers a list of type Object. (Inherited from SqlSmoObject.)
Public methodDropDrops the database.
Public methodDropAllPlanGuidesDrops all Plan Guides in a database.
Public methodDropBackupHistoryDrops the backup history for the database.
Protected methodDropImplDrops a SqlSmoObject. (Inherited from SqlSmoObject.)
Protected methodDropImplWorkerCalls the drop methods. (Inherited from SqlSmoObject.)
Public methodEnableAllPlanGuidesEnables all Plan Guides in a database.
Public methodEnumBackupSetFiles()Returns a DataTable listing files contained in a backup set.
Public methodEnumBackupSetFiles(Int32)Returns a Data table that lists the files in a backup set
Public methodEnumBackupSetsReturns a DataTable listing the backup sets associated with a database.
Public methodEnumCandidateKeysEnumerates a list of all candidate primary keys in the database, which can be referenced by a foreign key.
Public methodEnumDatabasePermissions()Enumerates a list of all permissions in the database.
Public methodEnumDatabasePermissions(String)Enumerates a list of permissions in the database for the specified user.
Public methodEnumDatabasePermissions(DatabasePermissionSet)Enumerates a list of permissions in the database for the specified permission set.
Public methodEnumDatabasePermissions(String, DatabasePermissionSet)Enumerates a list of permissions in the database for the specified user and a specified permission set.
Public methodEnumLocks()Enumerates a list of all current locks held on the database.
Public methodEnumLocks(Int32)Enumerates a list of current locks held on the database for a specified system process ID.
Public methodEnumLoginMappingsEnumerates a list of SQL Server logins for all the users in the database.
Public methodEnumMatchingSPs(String)Enumerates a list of stored procedures that contain the specified string in the definition.
Public methodEnumMatchingSPs(String, Boolean)Enumerates a list of stored procedures that contain the specified string in the definition.
Public methodEnumObjectPermissions()Enumerates a list of permissions for objects in the database.
Public methodEnumObjectPermissions(String)Enumerates a list of permissions for objects in the database that belong to the specified user.
Public methodEnumObjectPermissions(ObjectPermissionSet)Enumerates a list of permissions for objects in the database limited to the specified permission set.
Public methodEnumObjectPermissions(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 methodEnumObjects()Enumerates a list of objects in the database.
Public methodEnumObjects(DatabaseObjectTypes)Enumerates a list of objects in the database.
Public methodEnumObjects(DatabaseObjectTypes, SortOrder)Enumerates a list of objects in the database.
Protected methodEnumScriptImplEnumerates scripts specified by the so parameter. (Inherited from SqlSmoObject.)
Protected methodEnumScriptImplWorkerCalls the methods that enumerate scripts specified by the so parameter. (Inherited from SqlSmoObject.)
Protected methodEnumScriptImplWorkerSOChangedReturns an IEnumerable string describing the scripting options for an object. (Inherited from SqlSmoObject.)
Public methodEnumTransactions()Enumerates a list of open transactions on the database.
Public methodEnumTransactions(TransactionTypes)Enumerates a list of open transactions of a specified type on the database.
Public methodEnumWindowsGroups()Enumerates a list of Windows groups.
Public methodEnumWindowsGroups(String)Enumerates a list of Windows groups for a specified group.
Public methodEquals (Inherited from Object.)
Public methodExecuteNonQuery(StringCollection)Executes a batch in the context of the database where there are no results returned.
Public methodExecuteNonQuery(String)Executes a statement in the context of the database where there are no results returned.
Public methodExecuteNonQuery(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 methodExecuteNonQuery(String, ExecutionTypes)Executes a batch in the context of the database where there are no results returned for the specified execution type only.
Protected methodExecuteNonQuery(StringCollection, Boolean)Executes a batch in the context of the database where there are no results returned. (Inherited from SqlSmoObject.)
Public methodExecuteWithResults(StringCollection)Executes a batch in the context of the database where there are results returned.
Public methodExecuteWithResults(String)Executes a collection of batches in the context of the database where there are results returned.
Protected methodFinalize (Inherited from Object.)
Protected methodForceTextModeOnTextBodyEnforces text mode on the text body. (Inherited from ScriptNameObjectBase.)
Protected methodFormatSqlVariantFormats an object as SqlVariant type. (Inherited from SqlSmoObject.)
Protected methodGenerateDataSpaceFileStreamScriptGenerates a script to create data file. (Inherited from SqlSmoObject.)
Protected methodGenerateDataSpaceScriptGenerates a script to allocate space in the data file. (Inherited from SqlSmoObject.)
Protected methodGetBindDefaultScriptGets the script that binds defaults specified by the defSchema and defName parameters. (Inherited from SqlSmoObject.)
Protected methodGetBindRuleScriptGets the script that specifies the binding rules. (Inherited from SqlSmoObject.)
Protected methodGetBoolParameter(StringBuilder, ScriptingOptions, String, String, Int32)Assigns a Boolean parameter of the SqlSmoObject. (Inherited from SqlSmoObject.)
Protected methodGetBoolParameter(StringBuilder, ScriptingOptions, String, String, Int32, Boolean)Assigns a Boolean property of the SqlSmoObject. (Inherited from SqlSmoObject.)
Protected methodGetBraketNameForTextGets the bracket name. (Inherited from ScriptNameObjectBase.)
Protected methodGetDateTimeParameterAssigns the datetime property of the SqlSmoObject. (Inherited from SqlSmoObject.)
Protected methodGetDateTimeParameterAsIntAssigns the datetime property of the SqlSmoObject as an integer value if the datetime property is not null. (Inherited from SqlSmoObject.)
Protected methodGetDBNameGets the database name that is associated with the object. (Inherited from SqlSmoObject.)
Protected methodGetEnumParameterAssigns an enumeration property of the SqlSmoObject. (Inherited from SqlSmoObject.)
Protected methodGetFragOptionStringGets a FragmentationOption object as a string value. (Inherited from SqlSmoObject.)
Protected methodGetGuidParameterAssigns a Guid property of the SqlSmoObject. (Inherited from SqlSmoObject.)
Public methodGetHashCode (Inherited from Object.)
Protected methodGetIsSystemNamedGets a Boolean value that specifies whether the system is named. (Inherited from ScriptNameObjectBase.)
Protected methodGetIsTextDirtyDetermines whether the text value is consistent with stored value. (Inherited from ScriptNameObjectBase.)
Protected methodGetParameter(StringBuilder, ScriptingOptions, String, String, Int32)Assigns a parameter of the SqlSmoObject. (Inherited from SqlSmoObject.)
Protected methodGetParameter(StringBuilder, ScriptingOptions, String, String, Int32, Boolean)Assigns a parameter of the SqlSmoObject. (Inherited from SqlSmoObject.)
Protected methodGetPropValueGets a property value of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Protected methodGetPropValueOptionalGets a property value of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Protected methodGetPropValueOptionalAllowNullGets a property value of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Protected methodGetRealValueGets a property value of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Protected methodGetScriptIncludeExistsGets the script including the test for existence of type being scripted. (Inherited from ScriptNameObjectBase.)
Protected methodGetScriptingOptionsForCreateGets ScriptingOptions for the SqlSmoObject object. (Inherited from SqlSmoObject.)
Protected methodGetServerNameGets the name of the instance of SQL Server with which the object is associated. (Inherited from SqlSmoObject.)
Protected methodGetServerObjectGets the server of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Protected methodGetSqlServerVersionNameGets the version name of the instance of SQL Server with which the object is associated. (Inherited from SqlSmoObject.)
Protected methodGetStringParameter(StringBuilder, ScriptingOptions, String, String, Int32)Assigns a string parameter of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Protected methodGetStringParameter(StringBuilder, ScriptingOptions, String, String, Int32, Boolean)Assigns a string parameter of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Protected methodGetTextBody()Returns the text body. (Inherited from ScriptNameObjectBase.)
Protected methodGetTextBody(Boolean)Returns the text body. (Inherited from ScriptNameObjectBase.)
Protected methodGetTextForScript(ScriptingOptions, Boolean, String[])Gets the text for scripting. (Inherited from ScriptNameObjectBase.)
Protected methodGetTextForScript(ScriptingOptions, Boolean, String[], Boolean)Gets the text of script object. (Inherited from ScriptNameObjectBase.)
Protected methodGetTextHeaderReturns the text header. (Inherited from ScriptNameObjectBase.)
Protected methodGetTextModeDetermines whether the script name is using text mode. (Inherited from ScriptNameObjectBase.)
Protected methodGetTextProperty(String)Gets the property as text. (Inherited from ScriptNameObjectBase.)
Protected methodGetTextProperty(String, ScriptingOptions)Gets the property as text. (Inherited from ScriptNameObjectBase.)
Protected methodGetTimeSpanParameterAsIntAssigns a time span parameter of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Public methodGetTransactionCount()Gets the number of open transactions on the database.
Public methodGetTransactionCount(TransactionTypes)Gets the number of open transactions of a specified type on the database.
Public methodGetType (Inherited from Object.)
Protected methodGetUrnRecursive(StringBuilder)Assigns an Urn object of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Protected methodGetUrnRecursive(StringBuilder, UrnIdOption)Assigns an Urn object of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Public methodGrant(DatabasePermissionSet, String)Grants the specified set of permissions to the specified grantee on the database.
Public methodGrant(DatabasePermissionSet, String[])Grants the specified set of permissions to the specified grantees on the database.
Public methodGrant(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 methodGrant(DatabasePermissionSet, String[], Boolean)Grants access to the specified permission to the grantees and the ability to grant access to other users on the database.
Public methodGrant(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 methodGrant(DatabasePermissionSet, 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 methodImplInitializeInitializes the fields of the SqlSmoObject object. (Inherited from SqlSmoObject.)
Public methodInitialize()Initializes the object and forces the properties be loaded. (Inherited from SqlSmoObject.)
Public methodInitialize(Boolean)Initializes the object and forces the properties be loaded. (Inherited from SqlSmoObject.)
Public methodIsMemberDetermines whether the specified group or role belongs to the database.
Protected methodIsObjectDirtyDetermines whether the referenced object is consistent with the stored object. (Inherited from ScriptNameObjectBase.)
Protected methodIsObjectInitializedVerifies whether the object has been initialized. (Inherited from SqlSmoObject.)
Protected methodIsObjectInSpaceVerifies whether the object is isolated or connected to the instance of SQL Server. (Inherited from SqlSmoObject.)
Protected methodIsVersion80SP3Determines whether the version of SQL Server is SQL Server 2000 with SP3. (Inherited from SqlSmoObject.)
Protected methodIsVersion90AndAboveDetermines whether the version of SQL Server is SQL Server 2005 or later. (Inherited from SqlSmoObject.)
Protected methodMarkDroppedSets the SqlSmoState to dropped. (Inherited from SqlSmoObject.)
Protected methodMarkForDropImplSets the SqlSmoState to dropped. (Inherited from SqlSmoObject.)
Protected methodMemberwiseClone (Inherited from Object.)
Protected methodPostAlterMethod activated after the SqlSmoObject is altered. (Inherited from SqlSmoObject.)
Protected methodPostCreateMethod activated after the SqlSmoObject is created. (Inherited from SqlSmoObject.)
Protected methodPostDropMethod activated after the SqlSmoObject is dropped. (Inherited from SqlSmoObject.)
Public methodPrefetchObjects()Prefetches database objects.
Public methodPrefetchObjects(Type)Prefetches database objects of a specified type.
Public methodPrefetchObjects(Type, ScriptingOptions)Prefetches database objects of a specified type with scripting options.
Public methodRecalculateSpaceUsageRecalculates space usage.
Public methodRefreshUpdates the Database object. (Overrides ScriptNameObjectBase.Refresh().)
Public methodRemoveFullTextCatalogsRemoves full-text catalogs from the database.
Public methodRenameRenames the database.
Protected methodRenameImplIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed. (Inherited from NamedSmoObject.)
Protected methodRenameImplWorkerIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed. (Inherited from NamedSmoObject.)
Public methodRevoke(DatabasePermissionSet, String)Revokes a previously granted set of permissions from a grantee on the database.
Public methodRevoke(DatabasePermissionSet, String[])Revokes a previously granted set of permissions from a list of grantees on the database.
Public methodRevoke(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 methodRevoke(DatabasePermissionSet, 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 methodRevoke(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 methodRevoke(DatabasePermissionSet, 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 methodScript()Generates a Transact-SQL script that can be used to re-create the database.
Public methodScript(ScriptingOptions)Generates a Transact-SQL script that can be used to re-create the database as specified by the script options.
Protected methodScriptAlterAlters the SqlSmoObject according to the parameters. (Inherited from SqlSmoObject.)
Protected methodScriptAnsiQIScripts the database object in ANSI text. (Inherited from ScriptNameObjectBase.)
Protected methodScriptChangeOwnerThis method supports the SMO infrastructure and is not intended to be used directly from your code. (Inherited from NamedSmoObject.)
Protected methodScriptCreateAlters the SqlSmoObject according to the parameters. (Inherited from SqlSmoObject.)
Protected methodScriptDdlThrows InvalidSmoOperationException. (Inherited from SqlSmoObject.)
Protected methodScriptDropThrows InvalidSmoOperationException. (Inherited from SqlSmoObject.)
Protected methodScriptImpl()Gets a collection of scripts of the SqlSmoObject. (Inherited from SqlSmoObject.)
Protected methodScriptImpl(ScriptingOptions)Gets a collection of scripts of the SqlSmoObject. (Inherited from SqlSmoObject.)
Protected methodScriptImplWorkerGets a collection of scripts of the SqlSmoObject. (Inherited from SqlSmoObject.)
Protected methodScriptInformativeHeadersScripts the information headers. (Inherited from ScriptNameObjectBase.)
Protected methodScriptOwnerAlters the script owner authorization. (Inherited from NamedSmoObject.)
Protected methodScriptRenameThis method supports the SMO infrastructure and is not intended to be used directly from your code. (Inherited from NamedSmoObject.)
Protected methodSetCollectionTextModeSets the collection text mode. (Inherited from ScriptNameObjectBase.)
Public methodSetDefaultFileGroupSets the default file group for the database.
Public methodSetDefaultFileStreamFileGroupSets the default filestream group.
Public methodSetDefaultFullTextCatalogSets the default full-text catalog for the database.
Protected methodSetIsSystemNamedSets a Boolean value that specifies whether the system is named. (Inherited from ScriptNameObjectBase.)
Public methodSetOfflineSets the database offline.
Public methodSetOnlineSets the database online.
Public methodSetOwner(String)Sets the database owner.
Public methodSetOwner(String, Boolean)Sets the database owner.
Protected methodSetParentImplSets the parent of the SqlSmoObject to the newParent parameter. (Inherited from SqlSmoObject.)
Protected methodSetSchemaOwnedSets the schema owned value. (Inherited from NamedSmoObject.)
Public methodSetSnapshotIsolationSets the snapshot isolation level.
Protected methodSetTextBodySpecifies the text body. (Inherited from ScriptNameObjectBase.)
Protected methodSetTextHeaderSpecifies the text header. (Inherited from ScriptNameObjectBase.)
Protected methodSetTextModeSpecifies the text mode. (Inherited from ScriptNameObjectBase.)
Public methodShrinkShrinks the database.
Protected methodSwitchTextModeSwitches the text mode. (Inherited from ScriptNameObjectBase.)
Protected methodThrowIfTextIsDirtyForAlterThrows an exception of text has been modified and not persisted. (Inherited from ScriptNameObjectBase.)
Public methodToStringReturns a String that represents the referenced object. (Inherited from SqlSmoObject.)
Protected methodTouchImplNot implemented. (Inherited from SqlSmoObject.)
Public methodTruncateLogTruncates the database log.
Protected methodUnbindDefaultImplUnbinds the default columns of the SqlSmoObject. (Inherited from SqlSmoObject.)
Protected methodUnbindRuleImplUnbinds rules of the SqlSmoObject. (Inherited from SqlSmoObject.)
Public methodUpdateIndexStatisticsUpdates index statistics.
Public methodValidateValidates the state of an object. (Inherited from SmoObjectBase.)
Public methodValidateAllPlanGuides()Verifies the validity of the execution plans associated with the database.
Public methodValidateAllPlanGuides(DataTable)Verifies the validity of the execution plans associated with the database and returns validation report.
Top

  NameDescription
Public eventPropertyChangedRepresents the event that occurs when a property is changed. (Inherited from SqlSmoObject.)
Public eventPropertyMetadataChangedRepresents the event that occurs when property metadata changes. (Inherited from SqlSmoObject.)
Top

  NameDescription
Protected fieldm_ExtendedPropertiesRepresents a property that is defined to extend the properties provided by a SqlSmoObject. (Inherited from SqlSmoObject.)
Protected fieldsingletonParentRepresents the singleton parent. (Inherited from SqlSmoObject.)
Top

  NameDescription
Explicit interface implemetationPrivate methodIAlienObject.DiscoverDiscovers any dependencies. Do not reference this member directly in your code. It supports the SQL Server infrastructure. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate methodIAlienObject.GetDomainRootReturns the root of the domain. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate methodIAlienObject.GetParentGets 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 methodIAlienObject.GetPropertyTypeGets the type of the specified property. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate methodIAlienObject.GetPropertyValueGets the value of the specified property. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate methodIAlienObject.GetUrnGets the Unified Resource Name of the object. Do not reference this member directly in your code. It supports the SQL Server infrastructure. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate methodIAlienObject.ResolveGets the instance that contains the information about the object from the Unified Resource Name of the object. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate methodIAlienObject.SetObjectStateSets the object state to the specified SfcObjectState value. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate methodIAlienObject.SetPropertyValueSets the property value. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate methodISfcPropertyProvider.GetPropertySetGets the interface reference to the set of properties of this object. Do not reference this member directly in your code. It supports the SQL Server infrastructure. (Inherited from SqlSmoObject.)
Explicit interface implemetationPrivate propertyISfcSupportsDesignMode.IsDesignMode Gets a Boolean value that indicates whether the object supports design mode. Identified for informational purposes only. Not supported. Future compatibility is not guaranteed.
Top

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 and existing database.

  • Register the database in the Active Directory 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.

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()

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft