{"id":25486,"date":"2020-12-11T17:28:23","date_gmt":"2020-12-11T10:28:23","guid":{"rendered":"https:\/\/tom.ji42.com\/?p=25486"},"modified":"2020-12-11T17:28:23","modified_gmt":"2020-12-11T10:28:23","slug":"%e0%b8%84%e0%b8%b3%e0%b8%aa%e0%b8%b1%e0%b9%88%e0%b8%87%e0%b8%82%e0%b8%ad%e0%b8%87-sql-server","status":"publish","type":"post","link":"https:\/\/tom.tomwork.net\/?p=25486","title":{"rendered":"\u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07\u0e02\u0e2d\u0e07 SQL Server"},"content":{"rendered":"<p>\u0e01\u0e32\u0e23\u0e23\u0e31\u0e1a\u0e04\u0e48\u0e32\u00a0Indentity \u0e08\u0e32\u0e01\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e25\u0e48\u0e32\u0e2a\u0e38\u0e14\u0e17\u0e35\u0e48\u0e40\u0e1e\u0e34\u0e48\u0e21\u0e02\u0e36\u0e49\u0e19 \u0e2b\u0e25\u0e31\u0e07\u0e08\u0e32\u0e01\u0e17\u0e35\u0e48\u0e43\u0e0a\u0e49\u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07 INSERT \u0e40\u0e23\u0e32\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16\u0e2a\u0e48\u0e07\u0e04\u0e48\u0e32\u0e17\u0e35\u0e48\u0e40\u0e1b\u0e47\u0e19\u0e40\u0e25\u0e02\u0e25\u0e48\u0e32\u0e2a\u0e38\u0e14\u0e2d\u0e2d\u0e01\u0e21\u0e32\u0e08\u0e32\u0e01 store procedure \u0e44\u0e14\u0e49\u0e2b\u0e25\u0e32\u0e22\u0e27\u0e34\u0e18\u0e35\u0e14\u0e31\u0e07\u0e19\u0e35\u0e49<\/p>\n<ul>\n<li>SELECT\u00a0@@IDENTITY\u00a0\u0e2b\u0e23\u0e37\u0e2d<\/li>\n<li>SELECT IDENT_CURRENT(&#8216;\u0e0a\u0e37\u0e48\u0e2d\u0e15\u0e32\u0e23\u0e32\u0e07&#8217;) \u0e2b\u0e23\u0e37\u0e2d<\/li>\n<li>SELECT SCOPE_IDENTITY()<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<p>\u0e2b\u0e23\u0e37\u0e2d\u0e08\u0e30\u0e43\u0e0a\u0e49\u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07 DBCC CHECKIDENT (\u0e0a\u0e37\u0e48\u0e2d\u0e15\u0e32\u0e23\u0e32\u0e07, NORESEED)<br \/>\n\u0e0b\u0e36\u0e48\u0e07\u0e08\u0e30\u0e41\u0e2a\u0e14\u0e07\u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c\u0e2d\u0e2d\u0e01\u0e21\u0e32\u0e40\u0e1b\u0e47\u0e19:<br \/>\nChecking identity information: current identity value &#8216;1&#8217;, current column value &#8216;1&#8217;.<br \/>\nDBCC execution completed. If DBCC printed error messages, contact your system administrator.<\/p>\n<p>\u0e40\u0e23\u0e32\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16\u0e40\u0e2d\u0e32\u0e21\u0e32\u0e1b\u0e23\u0e31\u0e1a\u0e43\u0e0a\u0e49\u0e43\u0e19\u0e01\u0e32\u0e23\u0e23\u0e31\u0e1a\u0e04\u0e48\u0e32 Id (\u0e2a\u0e21\u0e21\u0e38\u0e15\u0e34 Id \u0e40\u0e1b\u0e47\u0e19\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e1f\u0e34\u0e25\u0e14\u0e4c\u0e40\u0e01\u0e47\u0e1a\u0e23\u0e2b\u0e31\u0e2a \u0e2a\u0e23\u0e49\u0e32\u0e07\u0e40\u0e1b\u0e47\u0e19 Integer \u0e41\u0e1a\u0e1a Indentity) \u0e02\u0e2d\u0e07\u0e23\u0e32\u0e22\u0e01\u0e32\u0e23\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e25\u0e48\u0e32\u0e2a\u0e38\u0e14\u0e2b\u0e25\u0e31\u0e07\u0e08\u0e32\u0e01\u0e17\u0e35\u0e48\u0e17\u0e33\u0e01\u0e32\u0e23\u0e40\u0e1e\u0e34\u0e48\u0e21\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e41\u0e25\u0e49\u0e27 \u0e40\u0e23\u0e32\u0e01\u0e47\u0e08\u0e30\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16\u0e2d\u0e48\u0e32\u0e19\u0e04\u0e48\u0e32 Id \u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e19\u0e33\u0e44\u0e1b\u0e43\u0e0a\u0e49\u0e07\u0e32\u0e19\u0e44\u0e14\u0e49\u0e15\u0e48\u0e2d\u0e44\u0e1b \u0e19\u0e2d\u0e01\u0e08\u0e32\u0e01\u0e19\u0e35\u0e49\u0e22\u0e31\u0e07\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16\u0e2b\u0e32\u0e04\u0e48\u0e32 Id \u0e25\u0e48\u0e32\u0e2a\u0e38\u0e14\u0e44\u0e14\u0e49\u0e2d\u0e35\u0e01\u0e2b\u0e25\u0e32\u0e22\u0e27\u0e34\u0e18\u0e35 \u0e40\u0e0a\u0e48\u0e19<\/p>\n<ul>\n<li>SELECT MAX(Id) FROM \u0e0a\u0e37\u0e48\u0e2d\u0e15\u0e32\u0e23\u0e32\u0e07<\/li>\n<li>SELECT TOP 1 Id\u00a0 FROM \u0e0a\u0e37\u0e48\u0e2d\u0e15\u0e32\u0e23\u0e32\u0e07<\/li>\n<\/ul>\n<p><a name=\"more\"><\/a><br \/>\n<strong>\u0e01\u0e32\u0e23\u0e15\u0e23\u0e27\u0e08\u0e2a\u0e2d\u0e1a\u0e40\u0e07\u0e37\u0e48\u0e2d\u0e19\u0e44\u0e02\u0e14\u0e49\u0e27\u0e22 EXISTS<\/strong><br \/>\n\u0e01\u0e23\u0e13\u0e35\u0e15\u0e49\u0e2d\u0e07\u0e01\u0e32\u0e23\u0e15\u0e23\u0e27\u0e08\u0e2a\u0e2d\u0e1a\u0e40\u0e07\u0e37\u0e48\u0e2d\u0e19\u0e44\u0e02\u0e27\u0e48\u0e32\u0e21\u0e35\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e2d\u0e22\u0e39\u0e48\u0e43\u0e19\u0e10\u0e32\u0e19\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e41\u0e25\u0e49\u0e27\u0e2b\u0e23\u0e37\u0e2d\u0e44\u0e21\u0e48\u0e40\u0e23\u0e32\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16\u0e43\u0e0a\u0e49\u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07 EXISTS \u0e0a\u0e48\u0e27\u0e22\u0e43\u0e19\u0e01\u0e32\u0e23\u0e15\u0e23\u0e27\u0e08\u0e2a\u0e2d\u0e1a\u0e44\u0e14\u0e49 \u0e15\u0e32\u0e21\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07<\/p>\n<blockquote><p>if\u00a0EXISTS\u00a0(select * from\u00a0\u0e0a\u0e37\u0e48\u0e2d\u0e15\u0e32\u0e23\u0e32\u0e07 where id = &#8216;123&#8217;)<br \/>\n&#8212;\u00a0\u0e01\u0e23\u0e13\u0e35\u0e21\u0e35\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e2d\u0e22\u0e39\u0e48\u0e41\u0e25\u0e49\u0e27<br \/>\nELSE<br \/>\n&#8212; \u0e01\u0e23\u0e13\u0e35\u0e22\u0e31\u0e07\u0e44\u0e21\u0e48\u0e21\u0e35\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25<\/p><\/blockquote>\n<p><strong>\u0e01\u0e32\u0e23\u0e2a\u0e38\u0e48\u0e21\u0e40\u0e25\u0e37\u0e2d\u0e01\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25 (Random)<\/strong><br \/>\n\u0e01\u0e23\u0e13\u0e35\u0e15\u0e49\u0e2d\u0e07\u0e01\u0e32\u0e23\u0e2a\u0e38\u0e48\u0e21\u0e40\u0e25\u0e37\u0e2d\u0e01\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e19\u0e33\u0e21\u0e32\u0e41\u0e2a\u0e14\u0e07\u0e40\u0e23\u0e32\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16\u0e43\u0e0a\u0e49 NEWID() \u0e40\u0e0a\u0e48\u0e19 SELECT top\u00a05 * FROM\u00a0\u0e0a\u0e37\u0e48\u0e2d\u0e15\u0e32\u0e23\u0e32\u0e07 ORDER BY\u00a0NEWID()<\/p>\n<p><strong>\u0e01\u0e32\u0e23\u0e19\u0e31\u0e1a\u0e08\u0e33\u0e19\u0e27\u0e19 Record \u0e2b\u0e25\u0e31\u0e07\u0e08\u0e32\u0e01\u0e23\u0e31\u0e19\u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07 Insert,\u00a0Update, Delete<\/strong><br \/>\n\/* how many rows were affected? *\/<br \/>\nSELECT @rc =\u00a0@@ROWCOUNT<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0e01\u0e32\u0e23\u0e23\u0e31\u0e1a\u0e04\u0e48\u0e32\u00a0Indentity \u0e08\u0e32\u0e01\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e25\u0e48\u0e32\u0e2a\u0e38\u0e14\u0e17\u0e35\u0e48\u0e40\u0e1e\u0e34\u0e48\u0e21\u0e02\u0e36\u0e49\u0e19 \u0e2b\u0e25\u0e31\u0e07\u0e08\u0e32\u0e01\u0e17\u0e35\u0e48\u0e43\u0e0a\u0e49\u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07 INSERT \u0e40\u0e23\u0e32\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16\u0e2a\u0e48\u0e07\u0e04\u0e48\u0e32\u0e17\u0e35\u0e48\u0e40\u0e1b\u0e47\u0e19\u0e40\u0e25\u0e02\u0e25\u0e48\u0e32\u0e2a\u0e38\u0e14\u0e2d\u0e2d\u0e01\u0e21\u0e32\u0e08\u0e32\u0e01 store procedure \u0e44\u0e14\u0e49\u0e2b\u0e25\u0e32\u0e22\u0e27\u0e34\u0e18\u0e35\u0e14\u0e31\u0e07\u0e19\u0e35\u0e49 SELECT\u00a0@@IDENTITY\u00a0\u0e2b\u0e23\u0e37\u0e2d SELECT IDENT_CURRENT(&#8216;\u0e0a\u0e37\u0e48\u0e2d\u0e15\u0e32\u0e23\u0e32\u0e07&#8217;) \u0e2b\u0e23\u0e37\u0e2d SELECT SCOPE_IDENTITY()<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[13],"tags":[],"class_list":["post-25486","post","type-post","status-publish","format-standard","hentry","category-13"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6cOVM-6D4","_links":{"self":[{"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/posts\/25486","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=25486"}],"version-history":[{"count":1,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/posts\/25486\/revisions"}],"predecessor-version":[{"id":25487,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/posts\/25486\/revisions\/25487"}],"wp:attachment":[{"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=25486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=25486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=25486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}