How do I SHOW CREATE TABLE in CUBRID?
MySQL provides SHOW CREATE TABLE syntax which shows the CREATE TABLE statement that creates the given table including all its CONSTRAINTS and INDEXes. How do I obtain the same information in CUBRID?
Edit: I need an SQL solution so that I can execute the query in scripting language such as PHP. So, CUBRID Manager solution is not exactly what I am looking for.
Considering that $object_name = 'stadium', the following will be the output.
CREATE TABLE stadium(
code INTEGER NOT NULL,
nation_code CHAR NOT NULL,
name VARCHAR(50) NOT NULL,
area NUMERIC,
seats INTEGER,
address VARCHAR(100),
CONSTRAINT pk_stadium_code PRIMARY KEY (code)
);Does anyone know pure PHP solution?
One solution would be in CUBRID Manager,
- by right clicking on a table,
- selecting the option Edit Table,
- and then the tab SQL Script.
CREATE TABLE "athlete"(
"code" integer AUTO_INCREMENT(16693,1),
"name" character varying(40) NOT NULL,
"gender" character(1),
"nation_code" character(3),
"event" character varying(30),
CONSTRAINT pk_athlete_code PRIMARY KEY("code")
);Another way to SHOW CREATE TABLE statement in CM is:
- right click on the table;
- choose "Copy SQL to Editor" -> "CREATE <table>"
or
choose "Copy SQL to Clipboard" -> "CREATE <table>"
If you need a solution working from PHP, the easiest way is to use the code from the CUBRID Database Schema application: http://code.google.com/p/cubrid-database-schema/
The application is open source, so you have full access to the code.
And you check how it works here: http://cubdbsch.cubrid.org/
A native PHP solution would be to use cubrid_schema() function. It will return the full information including column types, constraints, indexes, primary keys, etc. All you will need to do is to build the SQL from that return value which should be easy.
CUBRID 9.0 now supports "SHOW CREATE TABLE" statement. Here is the SHOW CREATE TABLE manual page.