开发者

Dynamically creating tables using information held in another table

I want to create a table in sql using the columns details (name, data type etc.) stored in 开发者_如何学C anther table in the database.


Depending on the database you can use the information schema tables. They hold the information you are looking for. Look for the table that describes the columns.

Postgres: http://www.postgresql.org/docs/8.4/interactive/information-schema.html

MySQL: http://dev.mysql.com/doc/refman/5.0/en/information-schema.html

You can query these tables and use 'select into' to insert the results into your other table.


One opinion is to create CREATE TABLE query and execute it in ADO.NET like shown here this


Try out this code

CREATE TABLE new_table AS SELECT * FROM old_table WHERE 1 = 2;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜