Sql 如何创建没有数据的重复表

Sql 如何创建没有数据的重复表,sql,sql-server-2005,Sql,Sql Server 2005,如何创建没有数据的重复表 旧表名--学生 newtablename--student1 请告诉我exat查询 谢谢, 丘吉尔..选择* SELECT TOP 0 * INTO student1 FROM student 进入学生1 来自学生 其中1=2 这将为您提供专栏, 但是索引和其他对象 将需要脚本 使用某种数据库工具。首先,您可以通过以下方式复制整个表: create table newtable as select * from oldtable where clause selec

如何创建没有数据的重复表

旧表名--学生

newtablename--student1

请告诉我exat查询

谢谢, 丘吉尔..

选择*
SELECT TOP 0 * INTO student1 FROM student
进入学生1 来自学生 其中1=2

这将为您提供专栏, 但是索引和其他对象 将需要脚本
使用某种数据库工具。

首先,您可以通过以下方式复制整个表:

create table newtable as select * from oldtable where clause
select * into (your_table_name) from student
复制整个表后,通过运行以下命令删除数据:

truncate table (your_table_name);
在上面的查询中,student1是一个表,该表包含已存在的表student的精确副本,student复制了整个数据

create table student1 as select * from student where 0=1;
查询只复制student表中的列,但不会复制任何数据


但请注意,您不能将约束和索引复制到oldtable中的newtable中,其中1=0。试试看,但是
student1
将不包含索引、约束和其他属于
student
表架构的内容。缺点是它不复制索引、PK、FK等。下面介绍如何复制完整的表结构:这对op没有帮助。它复制数据,也不复制像auto increment这样的属性
create table student1 as select * from student;
create table student1 as select * from student where 0=1;