comp • gb.mysql • _table • add

_Table.Add (gb.mysql)

Sub Add ( Table As String [ , Engine As String, Charset As String, Database As String ] )

Creates a table into the current database.

Table: Is the table name.
Engine: Is the storage engine to use.
Charset: Is the charset to use.

If Charset and Engine are not provided, then the default ones are used.

Note that to create a table, you have had to provide some fields information, as well as, index, primary key, etc.

See this page for information about fields.
See this page for supported storage engines.
See this page for supported charsets.
See this example.

Examples

Dim hCon As New Connection

With hCon
  .Type = "mysql"
  .Port = "3306"
  .Host = "localhost"
  .User = "root"
  .Password = "mypass"
  .Name = "Gambas"
  .Open()
End With

hCon.MySQL.Field.Add("actor_id", hCon.MySQL.DataTypes.UnsignedSmallInt, False,, True)
hCon.MySQL.Field.Add("first_name", hCon.MySQL.DataTypes.VarChar(45), False)
hCon.MySQL.Field.Add("last_name", hCon.MySQL.DataTypes.VarChar(45), False)
hCon.MySQL.Field.Add("last_update", hCon.MySQL.DataTypes.TimeStamp, False, "CURRENT_TIMESTAMP",, "CURRENT_TIMESTAMP")
hCon.MySQL.Field.PrimaryKey(["actor_id"])
hCon.MySQL.Field.Index("idx_actor_last_name", "last_name")
hCon.MySQL.Table.Add("actor", "InnoDB", hCon.MySQL.Charset)

MySQL statement:
' Create TABLE `actor` (
'   `actor_id` smallint(5) unsigned NOT NULL auto_increment,
'   `first_name` varchar(45) NOT NULL,
'   `last_name` varchar(45) NOT NULL,
'   `last_update` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
'   PRIMARY KEY(`actor_id`),
'   KEY `idx_actor_last_name` (`last_name`)
' )ENGINE = InnoDB Default CHARSET = utf8