1、修改字段的位置
比如:原表结构为a,b,c,要新增一个字段d,插入到b之后c之前,即a,b,d,c
1 --1、创建备份数据表 2 USE [QSIDB] 3 GO 4 5 /****** Object: Table [dbo].[tb_cspnD866_History] Script Date: 9/22/2022 6:03:55 PM ******/ 6 SET ANSI_NULLS ON 7 GO 8 9 SET QUOTED_IDENTIFIER ON 10 GO 11 12 CREATE TABLE [dbo].[tb_cspnD866_History_bak]( 13 [InsertedBy] [varchar](16) NULL, 14 [InsertedTime] [datetime] NULL, 15 [ActuallyInsertedTime] [datetime] NULL, 16 [UpdatedBy] [varchar](16) NULL, 17 [UpdatedTime] [datetime] NULL, 18 [PO] [varchar](30) NULL, 19 [CPN] [varchar](30) NULL, 20 [IPN] [varchar](50) NULL, 21 [CUSTOMER_LOT] [varchar](24) NULL, 22 [Subcon_CONTROL_LOT] [varchar](12) NULL, 23 [PKG] [varchar](30) NULL, 24 [DATE_CODE] [varchar](32) NULL, 25 [Stage] [varchar](6) NULL, 26 [QTY] [int] NULL, 27 [Hold_Reason] [varchar](500) NULL 28 ) ON [PRIMARY] 29 GO 30 --2、备份数据 31 insert into [tb_cspnD866_History_bak] select * from szsidb.sidb.dbo.tb_cspnD866_History 32 --3、删除表tb_cspnD866_History 33 drop table tb_cspnD866_History 34 35 --4、重新创建表tb_cspnD866_History 36 USE [QSIDB] 37 GO 38 39 /****** Object: Table [dbo].[tb_cspnD866_History] Script Date: 9/22/2022 6:03:55 PM ******/ 40 SET ANSI_NULLS ON 41 GO 42 43 SET QUOTED_IDENTIFIER ON 44 GO 45 46 CREATE TABLE [dbo].[tb_cspnD866_History]( 47 [InsertedBy] [varchar](16) NULL, 48 [InsertedTime] [datetime] NULL, 49 [ActuallyInsertedTime] [datetime] NULL, 50 [UpdatedBy] [varchar](16) NULL, 51 [UpdatedTime] [datetime] NULL, 52 [PO] [varchar](30) NULL, 53 [CPN] [varchar](30) NULL, 54 [IPN] [varchar](50) NULL, 55 [CUSTOMER_LOT] [varchar](24) NULL, 56 [Foundry_Lot_No] [varchar](30) NULL, 57 [Subcon_CONTROL_LOT] [varchar](12) NULL, 58 [PKG] [varchar](30) NULL, 59 [DATE_CODE] [varchar](32) NULL, 60 [Stage] [varchar](6) NULL, 61 [QTY] [int] NULL, 62 [Hold_Reason] [varchar](500) NULL 63 ) ON [PRIMARY] 64 GO 65 --5、重新导数据 66 insert tb_cspnD866_History(InsertedBy,InsertedTime,ActuallyInsertedTime,UpdatedBy,UpdatedTime,PO,CPN,IPN,CUSTOMER_LOT,Subcon_CONTROL_LOT,PKG,DATE_CODE,Stage,QTY,Hold_Reason) select InsertedBy,InsertedTime,ActuallyInsertedTime,UpdatedBy,UpdatedTime,PO,CPN,IPN,CUSTOMER_LOT,Subcon_CONTROL_LOT,PKG,DATE_CODE,Stage,QTY,Hold_Reason from tb_cspnD866_History_bak 67 --View Code
标签:History,varchar,cspnD866,修改,GO,NULL,tb,结构 From: https://www.cnblogs.com/kezhang/p/16721897.html