简体   繁体   English

在sql中动态创建表语句

[英]dynamically create table statement in sql

how to dynamically create a table with same columns as that of previous table. 如何动态创建与上一个表具有相同列的表。 in sql 在SQL中

select * into new_table from table where 1 = 0

select * into new_table from table

多数民众赞成在SQL2005

I believe that both of the above answers will work, but since you don't need the data and you just need the format, I would do the following: 我相信以上两个答案都可以使用,但是由于您不需要数据,而只需要格式,因此我将执行以下操作:

select * into new_table from table 从表中选择*进入new_table

TRUNCATE new_table; TRUNCATE new_table; -- I'm sure you know this, but just in case someone is new and doesn't, truncate leaves the table structure and removes all of the data. -我确定您知道这一点,但是如果万一有人是新来的但不是,则截断将保留表结构并删除所有数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM