The knoda scripting tutorial | ||
---|---|---|
Prev | Chapter 5. Tips and tricks |
To create a table, first get a new table object, set a name and set the mode to "createtable".
After that you can define new columns. First create it with new_column() and then set the type, name etc. When finished, create the table with create_table_now().
Example 5-4. create table
1 >>> table = db.new_table() 2 >>> table.set_name("my new table") 3 >>> table.setmode_createtable() 4 >>> col=table.new_column() 5 >>> col.set_columntype(hk_column.auto_inccolumn) 6 >>> col.set_name("id") 7 >>> col=table.new_column() 8 >>> col.set_name("name") 9 >>> table.create_table_now() 10 CREATE TABLE `my new table` ( `id` BIGINT(1) NOT NULL AUTO_INCREMENT , `name` BIGINT, PRIMARY KEY ( `id` ) ) 11 Table created 12 1 |