Condividi tramite


Tables Collection

Questa funzionalità verrà rimossa in una delle prossime versioni di Microsoft SQL Server. Evitare di utilizzare questa funzionalità in un nuovo progetto di sviluppo e prevedere interventi di modifica nelle applicazioni in cui è attualmente implementata.

The Tables collection contains Table objects that reference the system and user-defined tables of a Microsoft SQL Server database.

Modello di oggetti SQL-DMO in cui è visualizzato l'oggetto corrente

Properties

Count Property

 

Methods

Add Method

Refresh Method

Item Method

Remove Method (Collections)

ItemByID Method

 

Osservazioni

With the Tables collection, you can:

  • Create a table.
  • Remove a table.

To remove a table

  1. Get the Table object referencing the targeted table from the Tables collection by using the Item or ItemByID method. When extracting a Table object using the name of the referenced table, use the owner name to qualify the table name, as in:

    Set oTable = oDatabase.Tables("[Order Details]", "dbo")
    
  2. Use the Remove method of the Table object to remove the targeted table.

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

Set oTable = oDatabase.Tables("[Employees]")

Or:

Set oTable = oDatabase.Tables(1)

Additionally, when using name-based item selection, the Item method allows owner name qualification of the targeted SQL Server table, as shown earlier. When using the Remove method, the Tables collection does not support qualification of targeted object by owner name. It is suggested that you use the Item method to extract the target, then use the Remove method of the Table object to drop a table.

[!NOTA] Creating or removing SQL Server tables using the Tables collection requires appropriate privilege. The SQL Server login used for SQLServer object connection must be a member of the fixed role db_ddladmin or a role with greater privilege.