SQL::Schema::Table - A database table


SQL::Schema::Table - A database table


  my $table = SQL::Schema::Table->new(%attr);
  my $sql = $table->create_statement;
  print $sql;
  print "$table";


SQL::Schema::Table is a class for objects representing a database table. The methods of an instanciated object do allow to access the information within a database's data dictionary and to represent them as SQL create statements and the like using the proper SQL dialect.


  $table = SQL::Schema::Table->new(%attr);

The new method instanciates a table object. The object is an in memory representation of a (possible) database table. The attributes are given as key value pairs by the hash %attr. Possible keys are:

  key              required?   value description
  schema_name      no          The name of the schema for
  table_name       yes         The name of the table (without a
                               preceeding schema name).
  columns          yes         a reference to a list of
                               column objects
  pct_free         no          number
  pct_used         no          number
  ini_trans        no          number

These keys (except schema_name and columns) and their possible values correspond exactly to the data dictionary view user_tables and are described within Oracle's Server Reference.

Optionally the following keys and values which do have no counter part within the view user_tables are allowed for the attribute hash:

  key           value description
  constraints   a reference to a list of constraint objects
                (objects of type SQL::Schema::Constraint for instance)
  $table = SQL::Schema::Table->select($dbh,$name,$schema_name);

The select method fetches the attributes required by new from the database and returns the table object. (It calls new internally.)

If the table with the name $name could not be found within the database, the method returns undef.

The method's arguments are as follows:

A database handle as defined by DBI(3).

The name of the table without preceeding schema name.

The name of the database schema.


The following attribute methods do return the current value of the attributes (as handed over to the new method):

  $schema_name = $table->schema_name;
  $name = $table->name;
  @columns = $table->columns;
  $pct_free = $table->pct_free;
  $pct_used = $table->pct_used;
  $ini_trans = $table->ini_trans;
  @constraints = $table->constraints;
  my $qname = $table->qualified_name;

Returns the qualified name of the table which is the concatenation of schema_name and table_name with a in between if schema_name has been set. Otherwise only table_name is returned.

  $sql = $table->create_statement;
  $sql = "$table";

Returns a string containing an SQL statements for creation of this table. This method is overloaded with the string operator. So the two examples above are equivalent.

  $sql = $table->drop_statement;

Returns a string containing an SQL statement that would drop this table.


  SQL::Schema::Table is Copyright (C) 2000,
    Torsten Hentschel
    Windmuehlenweg 47
    44141 Dortmund
    Email: todd@bayleys.ping.de
  All rights reserved.
  You may distribute this package under the terms of either the GNU
  General Public License or the Artistic License, as specified in the
  Perl README file.


DBI(3), the SQL::Schema(3) manpage, the SQL::Schema::Table::Column(3) manpage, the SQL::Schema::Constraint(3) manpage

 SQL::Schema::Table - A database table