Classe Database
The Database object represents a SQL Server database.
Espace de noms : Microsoft.SqlServer.Management.Smo
Assembly : Microsoft.SqlServer.Smo (dans Microsoft.SqlServer.Smo.dll)
Syntaxe
'Déclaration
<EvaluationModeAttribute(AutomatedPolicyEvaluationMode.CheckOnSchedule)> _
<PhysicalFacetAttribute> _
Public NotInheritable Class Database _
Inherits ScriptNameObjectBase _
Implements ICreatable, IAlterable, IDroppable, IRenamable, _
IExtendedProperties, IScriptable, IDatabaseOptions, IDmfFacet, IPropertyDataDispatch
'Utilisation
Dim instance As Database
[EvaluationModeAttribute(AutomatedPolicyEvaluationMode.CheckOnSchedule)]
[PhysicalFacetAttribute]
public sealed class Database : ScriptNameObjectBase,
ICreatable, IAlterable, IDroppable, IRenamable, IExtendedProperties,
IScriptable, IDatabaseOptions, IDmfFacet, IPropertyDataDispatch
[EvaluationModeAttribute(AutomatedPolicyEvaluationMode::CheckOnSchedule)]
[PhysicalFacetAttribute]
public ref class Database sealed : public ScriptNameObjectBase,
ICreatable, IAlterable, IDroppable, IRenamable, IExtendedProperties,
IScriptable, IDatabaseOptions, IDmfFacet, IPropertyDataDispatch
[<SealedAttribute>]
[<EvaluationModeAttribute(AutomatedPolicyEvaluationMode.CheckOnSchedule)>]
[<PhysicalFacetAttribute>]
type Database =
class
inherit ScriptNameObjectBase
interface ICreatable
interface IAlterable
interface IDroppable
interface IRenamable
interface IExtendedProperties
interface IScriptable
interface IDatabaseOptions
interface IDmfFacet
interface IPropertyDataDispatch
end
public final class Database extends ScriptNameObjectBase implements ICreatable, IAlterable, IDroppable, IRenamable, IExtendedProperties, IScriptable, IDatabaseOptions, IDmfFacet, IPropertyDataDispatch
Notes
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
Tout membre statique public (Partagé dans Microsoft Visual Basic) de ce type est sûr dans le cadre des opérations à plusieurs threads. Tous les membres de l'instance ne sont pas garantis comme sûrs.
Exemples
'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()
Hiérarchie d'héritage
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
Sécurité des threads
Tous les membres publics static (Shared dans Visual Basic) de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.