MSSQL编程笔记六 表的完整复制
如果直接
select * into 目的数据库名.dbo.目的表名 from 原表名
复制的话,可以完整的复制表,但是有一个缺陷就是,表的主键和索引没了。
想要完整复制一张表,可以在sql server如下操作:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PWR_READING_DAILY_ANALYSIS]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[PWR_READING_DAILY_ANALYSIS]
GO
CREATE TABLE [dbo].[PWR_READING_DAILY_ANALYSIS] (
[FREAD_DATE] [datetime] NOT NULL ,
[FPTC_ID] [int] NOT NULL ,
[FTYPE] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[FAREA_COUNT] [int] NULL ,
[FCONCENTRATOR_COUNT] [int] NULL ,
[FMETER_COUNT] [int] NULL ,
[FCOLLECTOR_COUNT] [int] NULL ,
[FRESIDENT_COUNT] [int] NULL ,
[FBROKEN_METER_COUNT] [int] NULL ,
[FSTOP_METER_COUNT] [int] NULL ,
[FREADING_COUNT] [int] NULL ,
[FNOREADING_COUNT] [int] NULL ,
[FREADING_COUNT_PERCENT] [money] NULL
) ON [PRIMARY]
GO
CREATE INDEX [IX_PWR_READING_DAILY_ANALYSIS] ON [dbo].[PWR_READING_DAILY_ANALYSIS]([FPTC_ID]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
drop table [dbo].[PWR_READING_DAILY_ANALYSIS]
GO
CREATE TABLE [dbo].[PWR_READING_DAILY_ANALYSIS] (
[FREAD_DATE] [datetime] NOT NULL ,
[FPTC_ID] [int] NOT NULL ,
[FTYPE] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[FAREA_COUNT] [int] NULL ,
[FCONCENTRATOR_COUNT] [int] NULL ,
[FMETER_COUNT] [int] NULL ,
[FCOLLECTOR_COUNT] [int] NULL ,
[FRESIDENT_COUNT] [int] NULL ,
[FBROKEN_METER_COUNT] [int] NULL ,
[FSTOP_METER_COUNT] [int] NULL ,
[FREADING_COUNT] [int] NULL ,
[FNOREADING_COUNT] [int] NULL ,
[FREADING_COUNT_PERCENT] [money] NULL
) ON [PRIMARY]
GO
CREATE INDEX [IX_PWR_READING_DAILY_ANALYSIS] ON [dbo].[PWR_READING_DAILY_ANALYSIS]([FPTC_ID]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO