MsSQLserver中修改字段值系统自动生成的脚本

主要参考一下脚本的实现思路:
①创建临时表
②创建临时表
③向临时表插入数据
④删除原表
⑤临时表改名
  1. /* 为了防止任何可能出现的数据丢失问题,您应该先仔细检查此脚本,然后再在数据库设计器的上下文之外运行此脚本。*/
  2. BEGIN TRANSACTION
  3. SET QUOTED_IDENTIFIER ON
  4. SET ARITHABORT ON
  5. SET NUMERIC_ROUNDABORT OFF
  6. SET CONCAT_NULL_YIELDS_NULL ON
  7. SET ANSI_NULLS ON
  8. SET ANSI_PADDING ON
  9. SET ANSI_WARNINGS ON
  10. COMMIT
  11. BEGIN TRANSACTION
  12. GO
  13. CREATE TABLE dbo.Tmp_VBILL_HEAD
  14. (
  15. ID nvarchar(36) NOT NULL,
  16. TENANCY_ID nvarchar(6) NULL,
  17. VESSEL_VISIT_ID nvarchar(36) NOT NULL,
  18. I_SHIP_NO nvarchar(36) NULL,
  19. E_SHIP_NO nvarchar(36) NULL,
  20. I_E_ID nvarchar(4) NOT NULL,
  21. BILL_NO nvarchar(40) NOT NULL,
  22. BILL_TYPE nvarchar(6) NOT NULL,
  23. ORDER_NO nvarchar(24) NULL,
  24. TRADE_ID nvarchar(4) NULL,
  25. HANG_PLACE_COD nvarchar(10) NULL,
  26. CUSTOM_COD nvarchar(10) NULL,
  27. LINE_ID nvarchar(10) NULL,
  28. FEE_CLIENT_COD nvarchar(15) NULL,
  29. SHIPPER nvarchar(4000) NULL,
  30. CONSIGNEE nvarchar(4000) NULL,
  31. NOTIFY nvarchar(4000) NULL,
  32. SHIPPER_ADDR nvarchar(200) NULL,
  33. CONSIGNEE_ADDR nvarchar(200) NULL,
  34. NOTIFY_ADDR nvarchar(200) NULL,
  35. PAYER nvarchar(10) NULL,
  36. PAYER_PLACE nvarchar(80) NULL,
  37. DELV_TERM nvarchar(24) NULL,
  38. LOADING_TIME ntext NULL,
  39. DISCHING_TIME ntext NULL,
  40. TRANS_FLAG nchar(1) NOT NULL,
  41. TRANS_TYPE nvarchar(6) NULL,
  42. LCL_FLAG nchar(1) NOT NULL,
  43. LCL_NO nvarchar(40) NULL,
  44. SOC_FLAG nchar(1) NULL,
  45. EMPTY_FLAG nchar(1) NULL,
  46. CUSTOM_STATE nvarchar(10) NULL,
  47. LOAD_TYPE nvarchar(10) NULL,
  48. PRE_VESSEL_NAME nvarchar(80) NULL,
  49. PRE_VESSLE_VOY nvarchar(10) NULL,
  50. LOAD_NOTE nvarchar(100) NULL,
  51. POR nvarchar(5) NULL,
  52. POR_NAME nvarchar(80) NULL,
  53. POS nvarchar(5) NULL,
  54. POS_NAME nvarchar(80) NULL,
  55. POL nvarchar(5) NULL,
  56. POL_NAME nvarchar(80) NULL,
  57. POD nvarchar(5) NULL,
  58. POD_NAME nvarchar(80) NULL,
  59. PODEST nvarchar(5) NULL,
  60. PODEST_NAME nvarchar(80) NULL,
  61. POT nvarchar(5) NULL,
  62. POT_NAME nvarchar(80) NULL,
  63. SEQ_NO numeric(11, 0) NULL,
  64. QUANTITY numeric(11, 0) NULL,
  65. CNTR_OPER_ID nvarchar(10) NULL,
  66. RECEIVER nvarchar(100) NULL,
  67. SENDER nvarchar(50) NULL,
  68. FORWARDER nvarchar(50) NULL,
  69. SPOD nvarchar(5) NULL,
  70. CARGO_ID nvarchar(35) NULL,
  71. RELEASE_FLAG nchar(1) NOT NULL,
  72. EXIT_CUSTOM_FLAG nchar(1) NOT NULL,
  73. FEE_ID nchar(1) NOT NULL,
  74. PRE_VOYAGE_NO nvarchar(36) NULL,
  75. TRANS_VOYAGE_NO nvarchar(36) NULL,
  76. PHASE nvarchar(6) NULL,
  77. GOODS_NOTES nvarchar(255) NULL,
  78. PIECES numeric(14, 4) NULL,
  79. WEIGHT numeric(14, 4) NULL,
  80. VOLUME numeric(14, 4) NULL,
  81. MARKS nvarchar(60) NULL,
  82. PKG nvarchar(10) NULL,
  83. NOTES nvarchar(1000) NULL,
  84. CREATED_BY nvarchar(36) NULL,
  85. CREATED_ON date NULL,
  86. UPDATED_BY nvarchar(36) NULL,
  87. UPDATED_ON datetime NULL,
  88. RELEASE_WAY nvarchar(60) NULL,
  89. RELEASE_NOTES nvarchar(200) NULL,
  90. LOCK_FLAG nchar(1) NULL,
  91. LOCK_MAN nvarchar(36) NULL,
  92. LOCK_DTE ntext NULL,
  93. LOCK_NOTES nvarchar(200) NULL,
  94. NOTICE_FLAG nchar(1) NULL,
  95. NOTICE_FAX nvarchar(50) NULL,
  96. NOTICE_TEL nvarchar(50) NULL,
  97. NOTICE_DTE ntext NULL,
  98. DELIVERY_MAN nvarchar(36) NULL,
  99. DELIVERY_DTE ntext NULL,
  100. DELIVERY_NOTES nvarchar(200) NULL,
  101. DELIVERY_FLAG nchar(1) NULL,
  102. SIGN_FLAG nchar(1) NULL,
  103. SIGN_MAN nvarchar(36) NULL,
  104. SIGN_DTE ntext NULL,
  105. SIGN_NOTES nvarchar(200) NULL,
  106. CARRY_FLAG nchar(1) NULL,
  107. ATTRI_FLAG nchar(1) NULL,
  108. ATTRI_NEXT_FLAG nchar(1) NULL,
  109. LD_TERM nvarchar(24) NULL,
  110. TRADE_TERM nvarchar(24) NULL,
  111. QUARANTINE_TERM nvarchar(24) NULL,
  112. SIGN_POS nvarchar(5) NULL,
  113. SIGN_POS_NAME nvarchar(80) NULL,
  114. FEE_CONTRACT_NO nvarchar(50) NULL
  115. ) ON [PRIMARY]
  116. TEXTIMAGE_ON [PRIMARY]
  117. GO
  118. ALTER TABLE dbo.Tmp_VBILL_HEAD SET (LOCK_ESCALATION = TABLE)
  119. GO
  120. IF EXISTS(SELECT * FROM dbo.VBILL_HEAD)
  121. EXEC('INSERT INTO dbo.Tmp_VBILL_HEAD (ID, TENANCY_ID, VESSEL_VISIT_ID, I_SHIP_NO, E_SHIP_NO, I_E_ID, BILL_NO, BILL_TYPE, ORDER_NO, TRADE_ID, HANG_PLACE_COD, CUSTOM_COD, LINE_ID, FEE_CLIENT_COD, SHIPPER, CONSIGNEE, NOTIFY, SHIPPER_ADDR, CONSIGNEE_ADDR, NOTIFY_ADDR, PAYER, PAYER_PLACE, DELV_TERM, LOADING_TIME, DISCHING_TIME, TRANS_FLAG, TRANS_TYPE, LCL_FLAG, LCL_NO, SOC_FLAG, EMPTY_FLAG, CUSTOM_STATE, LOAD_TYPE, PRE_VESSEL_NAME, PRE_VESSLE_VOY, LOAD_NOTE, POR, POR_NAME, POS, POS_NAME, POL, POL_NAME, POD, POD_NAME, PODEST, PODEST_NAME, POT, POT_NAME, SEQ_NO, QUANTITY, CNTR_OPER_ID, RECEIVER, SENDER, FORWARDER, SPOD, CARGO_ID, RELEASE_FLAG, EXIT_CUSTOM_FLAG, FEE_ID, PRE_VOYAGE_NO, TRANS_VOYAGE_NO, PHASE, GOODS_NOTES, PIECES, WEIGHT, VOLUME, MARKS, PKG, NOTES, CREATED_BY, CREATED_ON, UPDATED_BY, UPDATED_ON, RELEASE_WAY, RELEASE_NOTES, LOCK_FLAG, LOCK_MAN, LOCK_DTE, LOCK_NOTES, NOTICE_FLAG, NOTICE_FAX, NOTICE_TEL, NOTICE_DTE, DELIVERY_MAN, DELIVERY_DTE, DELIVERY_NOTES, DELIVERY_FLAG, SIGN_FLAG, SIGN_MAN, SIGN_DTE, SIGN_NOTES, CARRY_FLAG, ATTRI_FLAG, ATTRI_NEXT_FLAG, LD_TERM, TRADE_TERM, QUARANTINE_TERM, SIGN_POS, SIGN_POS_NAME, FEE_CONTRACT_NO)
  122. SELECT ID, TENANCY_ID, VESSEL_VISIT_ID, I_SHIP_NO, E_SHIP_NO, I_E_ID, BILL_NO, BILL_TYPE, ORDER_NO, TRADE_ID, HANG_PLACE_COD, CUSTOM_COD, LINE_ID, FEE_CLIENT_COD, SHIPPER, CONSIGNEE, NOTIFY, SHIPPER_ADDR, CONSIGNEE_ADDR, NOTIFY_ADDR, PAYER, PAYER_PLACE, DELV_TERM, LOADING_TIME, DISCHING_TIME, TRANS_FLAG, TRANS_TYPE, LCL_FLAG, LCL_NO, SOC_FLAG, EMPTY_FLAG, CUSTOM_STATE, LOAD_TYPE, PRE_VESSEL_NAME, PRE_VESSLE_VOY, LOAD_NOTE, POR, POR_NAME, POS, POS_NAME, POL, POL_NAME, POD, POD_NAME, PODEST, PODEST_NAME, POT, POT_NAME, SEQ_NO, QUANTITY, CNTR_OPER_ID, RECEIVER, SENDER, FORWARDER, SPOD, CARGO_ID, RELEASE_FLAG, EXIT_CUSTOM_FLAG, FEE_ID, PRE_VOYAGE_NO, TRANS_VOYAGE_NO, PHASE, GOODS_NOTES, PIECES, WEIGHT, VOLUME, MARKS, PKG, NOTES, CREATED_BY, CONVERT(date, CREATED_ON), UPDATED_BY, UPDATED_ON, RELEASE_WAY, RELEASE_NOTES, LOCK_FLAG, LOCK_MAN, LOCK_DTE, LOCK_NOTES, NOTICE_FLAG, NOTICE_FAX, NOTICE_TEL, NOTICE_DTE, DELIVERY_MAN, DELIVERY_DTE, DELIVERY_NOTES, DELIVERY_FLAG, SIGN_FLAG, SIGN_MAN, SIGN_DTE, SIGN_NOTES, CARRY_FLAG, ATTRI_FLAG, ATTRI_NEXT_FLAG, LD_TERM, TRADE_TERM, QUARANTINE_TERM, SIGN_POS, SIGN_POS_NAME, FEE_CONTRACT_NO FROM dbo.VBILL_HEAD WITH (HOLDLOCK TABLOCKX)')
  123. GO
  124. DROP TABLE dbo.VBILL_HEAD
  125. GO
  126. EXECUTE sp_rename N'dbo.Tmp_VBILL_HEAD', N'VBILL_HEAD', 'OBJECT'
  127. GO
  128. COMMIT
  129. select Has_Perms_By_Name(N'dbo.VBILL_HEAD', 'Object', 'ALTER') as ALT_Per, Has_Perms_By_Name(N'dbo.VBILL_HEAD', 'Object', 'VIEW DEFINITION') as View_def_Per, Has_Perms_By_Name(N'dbo.VBILL_HEAD', 'Object', 'CONTROL') as Contr_Per






posted @ 2016-12-17 16:57  scown  阅读(1060)  评论(0编辑  收藏  举报