Search code examples
c#mysqldatabaseremote-servermysql.data

Create MySql database with TEXT column


I'm creating MySql database table from C# desktop application on remote server. I would like to make long records for columns content. I guess TEXT type must be suitable for this, but I'm not sure, how to set it from my createTableQuery string, instead varchar(120):

string createTableQuery = string.Format(@"CREATE TABLE `{0}` (
   `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
   `slots` varchar(120) NOT NULL DEFAULT '',
   `vectors` varchar(120) NOT NULL DEFAULT '',
   PRIMARY KEY (`id`),
   KEY `id` (`id`)) 
   ENGINE = MyISAM AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8;", "tab");

Or maybe I should use some different type...

Any advice and example would be useful


Solution

  • It would be:

    string createTableQuery = string.Format(@"CREATE TABLE `{0}` (
    `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
    `slots` TEXT NOT NULL DEFAULT '',
    `vectors` TEXT NOT NULL DEFAULT '',
    PRIMARY KEY (`id`),
    KEY `id` (`id`)) 
    ENGINE = MyISAM AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8;", "tab");