{"id":2442,"date":"2015-01-16T12:04:29","date_gmt":"2015-01-16T04:04:29","guid":{"rendered":"http:\/\/jason695.why3s.tw\/wordpress\/?p=2442"},"modified":"2015-01-16T12:59:24","modified_gmt":"2015-01-16T04:59:24","slug":"set-identity_insert-tablename-on%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85","status":"publish","type":"post","link":"https:\/\/jason695.why3s.tw\/wordpress\/2015\/01\/16\/set-identity_insert-tablename-on%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85\/","title":{"rendered":"set IDENTITY_INSERT [tablename] ON\u6ce8\u610f\u4e8b\u9805"},"content":{"rendered":"<p><a href=\"https:\/\/jonesyeh.wordpress.com\/2014\/01\/20\/set-identity_insert-tablename-on%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A0%85\/\" target=\"_blank\">https:\/\/jonesyeh.wordpress.com\/2014\/01\/20\/set-identity_insert-tablename-on%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A0%85\/<\/a><\/p>\n<pre class=\"lang:tsql decode:true  \">\u2013step 1:\u5efa\u7acb\u66ab\u5b58\u8cc7\u6599\u8868\r\nCREATE TABLE [#tp](\r\n    [user_seq] [int] IDENTITY(1,1) NOT NULL,\r\n    [user_id] [varchar](10) NOT NULL,\r\n    [user_name] [nvarchar](30) NOT NULL,\r\n    [org_key] [varchar](10) NULL,\r\n    [org_relation_seq] [int] NULL,\r\n    [org_path] [varchar](255) NULL,\r\n    [org_path_desc] [nvarchar](255) NULL,\r\n    [user_type_key] [varchar](10) NULL,\r\n    [job_key] [varchar](10) NULL,\r\n    [level_key] [varchar](10) NULL,\r\n    [code_group_key] [varchar](10) NOT NULL,\r\n    [code_group_type_key] [varchar](10) NOT NULL,\r\n    [position_date] [date] NULL,\r\n    [begin_time] [datetime2](7) NOT NULL,\r\n    [end_time] [datetime2](7) NULL,\r\n  PRIMARY KEY NONCLUSTERED \r\n(\r\n    [user_seq] ASC\r\n)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]\r\n) ON [PRIMARY]\r\n\r\n\u2013step2:\u5f9e\u5be6\u9ad4\u8cc7\u6599\u8868\u532f\u5165\u5230\u66ab\u5b58\u8cc7\u6599\u8868\r\ninsert into [#tp]\r\nselect  * from [comm].[tb_user_dim]\r\n\u2013\u57f7\u884c\u5931\u6557(\u4f4d\u65bc\u8cc7\u6599\u8868 \u2018#tp\u2019 \u7684\u8b58\u5225\u6b04\u4f4d\u5176\u5916\u986f\u503c\u53ea\u6709\u7576\u4f7f\u7528\u4e86\u8cc7\u6599\u884c\u6e05\u55ae\u4e14 IDENTITY_INSERT \u70ba ON \u6642\u624d\u80fd\u6307\u5b9a\u3002)\r\n\r\n\u2013step3:\u8a2d\u5b9aIDENTITY_INSERT=ON\r\nset IDENTITY_INSERT [#tp] ON\r\n\r\n\u2013step4:\u5f9e\u5be6\u9ad4\u8cc7\u6599\u8868\u532f\u5165\u5230\u66ab\u5b58\u8cc7\u6599\u8868\r\ninsert into [#tp]\r\nselect  * from [comm].[tb_user_dim]\r\n\u2013\u57f7\u884c\u5931\u6557(\u4f4d\u65bc\u8cc7\u6599\u8868 \u2018#tp\u2019 \u7684\u8b58\u5225\u6b04\u4f4d\u5176\u5916\u986f\u503c\u53ea\u6709\u7576\u4f7f\u7528\u4e86\u8cc7\u6599\u884c\u6e05\u55ae\u4e14 IDENTITY_INSERT \u70ba ON \u6642\u624d\u80fd\u6307\u5b9a\u3002)\r\n\u2013\u5f9e\u4ee5\u4e0a\u8a9e\u6cd5\u9084\u662f\u6703\u5931\u6557\uff0c\u539f\u56e0\u662finsert into \u7684\u8cc7\u6599\u8868\u9700\u8981\u6307\u5b9a\u8cc7\u6599\u884c\u540d\u7a31\r\n\r\n\u2013step5 \u4fee\u6539insert into\u8a9e\u6cd5\r\nset IDENTITY_INSERT [#tp] ON\r\ninsert into [#tp]\r\n([user_seq]\r\n      ,[user_id]\r\n      ,[user_name]\r\n      ,[org_key]\r\n      ,[org_relation_seq]\r\n      ,[org_path]\r\n      ,[org_path_desc]\r\n      ,[user_type_key]\r\n      ,[job_key]\r\n      ,[level_key]\r\n      ,[code_group_key]\r\n      ,[code_group_type_key]\r\n      ,[position_date]\r\n      ,[begin_time]\r\n      ,[end_time])\r\nselect  * from [comm].[tb_user_dim]\r\n\u2013(862 \u500b\u8cc7\u6599\u5217\u53d7\u5230\u5f71\u97ff)\r\n\r\ndrop table [#tp]<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/jonesyeh.wordpress.com\/2014\/01\/20\/set-identity_ &hellip; <a href=\"https:\/\/jason695.why3s.tw\/wordpress\/2015\/01\/16\/set-identity_insert-tablename-on%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587 <span class=\"screen-reader-text\">set IDENTITY_INSERT [tablename] ON\u6ce8\u610f\u4e8b\u9805<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[47],"tags":[],"class_list":["post-2442","post","type-post","status-publish","format-standard","hentry","category-sql-server","no-featured-image"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts\/2442","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/comments?post=2442"}],"version-history":[{"count":0,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts\/2442\/revisions"}],"wp:attachment":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/media?parent=2442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/categories?post=2442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/tags?post=2442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}