You can call the CreateTable operation to create a table based on the specified table schema information.

When creating a table in Table Store, you must specify the primary key of the table. A primary key contains one to four primary key columns. Each primary key column has a name and a type.

Method

       Description: You can call this method to create a table based on the specified table schema information.

        ``table_meta`` is an instance of the ``tablestore.metadata.TableMeta`` class. It contains the table name and primary key schema.
        For more information, see the documentation for the ``TableMeta`` class. After you create a table, it takes about 1 minute to load the partitions. After that, you can perform table operations.
        ``table_options`` is an instance of the ``tablestore.metadata.TableOptions`` class. It contains the time_to_live, max_version, and max_time_deviation parameters.
        ``reserved_throughput`` is an instance of the ``tablestore.metadata.ReservedThroughput`` class. It specifies the reserved read throughput and reserved write throughput.

        Return value: none.
		
		def create_table(self, table_meta, reserved_throughput):
Note After the table is created in Table Store, it takes several seconds to load the table. Do not perform any operations during this period.

Example

The following code provides an example of how to create a table. In this example, a table with two primary key columns is created. Specifically, time_to_live is set to 31,536,000 seconds (one year), max_version to 3, max_time_deviation to 86,400 seconds (one day), and reserved_throughput to (0,0).

	# Create a schema for the primary key columns, including the quantity, names, and types of primary keys.
	# The first primary key column (partition column) is named pk0 and of the integer type.
	# The second primary key column is named pk1 and of the integer type. You can also set the column to the string or binary type.
	schema_of_primary_key = [('pk0', 'INTEGER'), ('pk1', 'INTEGER')]

	# Create a tableMeta object based on the table name and the schema of primary key columns.
	table_meta = TableMeta('SampleTable', schema_of_primary_key)
	
	# Create TableOptions. Set time_to_live to 31,536,000 seconds (data is cleared automatically when expired), max_version to 3, and max_time_deviation to 86,400 seconds (one day).
	table_options = TableOptions(31536000, 3, 86400)

	# Set both the reserved read throughput and reserved write throughput to 0.
	reserved_throughput = ReservedThroughput(CapacityUnit(0, 0))

	# Call the create_table method of the client. If no exception is thrown, the operation is successful. If an exception is thrown, the operation fails.
	try:
		ots_client.create_table(table_meta, table_options, reserved_throughput)
		print "create table succeeded"
	# Handle any exception that is thrown.
	except Exception:
		print "create table failed."

You can obtain the full sample code at CreateTable@GitHub.