2012-07-22 105 views
2

在運行下面的SQL查詢 -WITH關鍵字是必需的

INSERT INTO Countries ('sno', 'Name') VALUES 
(1, 'Afghanistan'), 
(2, 'Albania'), 
(3, 'Algeria'), 
(4, 'American Samoa'), 
(5, 'Andorra'), 
(6, 'Angola'), 
(7, 'Anguilla'), 
(8, 'Antarctica'), 
(9, 'Antigua and Barbuda'), 
(10, 'Argentina'), 
(11, 'Armenia'), 
(12, 'Armenia'), 
(13, 'Aruba'), 
(14, 'Australia'), 
(15, 'Austria'), 
(16, 'Azerbaijan'), 
(17, 'Azerbaijan'), 
(18, 'Bahamas'), 
(19, 'Bahrain'), 
(20, 'Bangladesh'), 
(21, 'Barbados'), 
(22, 'Belarus'), 
(23, 'Belgium'), 
(24, 'Belize'), 
(25, 'Benin'), 
(26, 'Bermuda'), 
(27, 'Bhutan'), 
(28, 'Bolivia'), 
(29, 'Bosnia and Herzegovina'), 
(30, 'Botswana'), 
(31, 'Bouvet Island'), 
(32, 'Brazil'), 
(33, 'British Indian Ocean Territory'), 
(34, 'Brunei Darussalam'), 
(35, 'Bulgaria'), 
(36, 'Burkina Faso'), 
(37, 'Burundi'), 
(38, 'Cambodia'), 
(39, 'Cameroon'), 
(40, 'Canada'), 
(41, 'Cape Verde'), 
(42, 'Cayman Islands'), 
(43, 'Central African Republic'), 
(44, 'Chad'), 
(45, 'Chile'), 
(46, 'China'), 
(47, 'Christmas Island'), 
(48, 'Cocos (Keeling) Islands'), 
(49, 'Colombia'), 
(50, 'Comoros'), 
(51, 'Congo'), 
(52, 'Congo, The Democratic Republic of The'), 
(53, 'Cook Islands'), 
(54, 'Costa Rica'), 
(55, 'Cote Divoire'), 
(56, 'Croatia'), 
(57, 'Cuba'), 
(58, 'Cyprus'), 
(59, 'Cyprus'), 
(60, 'Czech Republic'), 
(61, 'Denmark'), 
(62, 'Djibouti'), 
(63, 'Dominica'), 
(64, 'Dominican Republic'), 
(65, 'Easter Island'), 
(66, 'Ecuador'), 
(67, 'Egypt'), 
(68, 'El Salvador'), 
(69, 'Equatorial Guinea'), 
(70, 'Eritrea'), 
(71, 'Estonia'), 
(72, 'Ethiopia'), 
(73, 'Falkland Islands (Malvinas)'), 
(74, 'Faroe Islands'), 
(75, 'Fiji'), 
(76, 'Finland'), 
(77, 'France'), 
(78, 'French Guiana'), 
(79, 'French Polynesia'), 
(80, 'French Southern Territories'), 
(81, 'Gabon'), 
(82, 'Gambia'), 
(83, 'Georgia'), 
(84, 'Georgia'), 
(85, 'Germany'), 
(86, 'Ghana'), 
(87, 'Gibraltar'), 
(88, 'Greece'), 
(89, 'Greenland'), 
(90, 'Greenland'), 
(91, 'Grenada'), 
(92, 'Guadeloupe'), 
(93, 'Guam'), 
(94, 'Guatemala'), 
(95, 'Guinea'), 
(96, 'Guinea-bissau'), 
(97, 'Guyana'), 
(98, 'Haiti'), 
(99, 'Heard Island and Mcdonald Islands'), 
(100, 'Honduras'), 
(101, 'Hong Kong'), 
(102, 'Hungary'), 
(103, 'Iceland'), 
(104, 'India'), 
(105, 'Indonesia'), 
(106, 'Indonesia'), 
(107, 'Iran'), 
(108, 'Iraq'), 
(109, 'Ireland'), 
(110, 'Israel'), 
(111, 'Italy'), 
(112, 'Jamaica'), 
(113, 'Japan'), 
(114, 'Jordan'), 
(115, 'Kazakhstan'), 
(116, 'Kazakhstan'), 
(117, 'Kenya'), 
(118, 'Kiribati'), 
(119, 'Korea, North'), 
(120, 'Korea, South'), 
(121, 'Kosovo'), 
(122, 'Kuwait'), 
(123, 'Kyrgyzstan'), 
(124, 'Laos'), 
(125, 'Latvia'), 
(126, 'Lebanon'), 
(127, 'Lesotho'), 
(128, 'Liberia'), 
(129, 'Libyan Arab Jamahiriya'), 
(130, 'Liechtenstein'), 
(131, 'Lithuania'), 
(132, 'Luxembourg'), 
(133, 'Macau'), 
(134, 'Macedonia'), 
(135, 'Madagascar'), 
(136, 'Malawi'), 
(137, 'Malaysia'), 
(138, 'Maldives'), 
(139, 'Mali'), 
(140, 'Malta'), 
(141, 'Marshall Islands'), 
(142, 'Martinique'), 
(143, 'Mauritania'), 
(144, 'Mauritius'), 
(145, 'Mayotte'), 
(146, 'Mexico'), 
(147, 'Micronesia, Federated States of'), 
(148, 'Moldova, Republic of'), 
(149, 'Monaco'), 
(150, 'Mongolia'), 
(151, 'Montenegro'), 
(152, 'Montserrat'), 
(153, 'Morocco'), 
(154, 'Mozambique'), 
(155, 'Myanmar'), 
(156, 'Namibia'), 
(157, 'Nauru'), 
(158, 'Nepal'), 
(159, 'Netherlands'), 
(160, 'Netherlands Antilles'), 
(161, 'New Caledonia'), 
(162, 'New Zealand'), 
(163, 'Nicaragua'), 
(164, 'Niger'), 
(165, 'Nigeria'), 
(166, 'Niue'), 
(167, 'Norfolk Island'), 
(168, 'Northern Mariana Islands'), 
(169, 'Norway'), 
(170, 'Oman'), 
(171, 'Pakistan'), 
(172, 'Palau'), 
(173, 'Palestinian Territory'), 
(174, 'Panama'), 
(175, 'Papua New Guinea'), 
(176, 'Paraguay'), 
(177, 'Peru'), 
(178, 'Philippines'), 
(179, 'Pitcairn'), 
(180, 'Poland'), 
(181, 'Portugal'), 
(182, 'Puerto Rico'), 
(183, 'Qatar'), 
(184, 'Reunion'), 
(185, 'Romania'), 
(186, 'Russia'), 
(187, 'Russia'), 
(188, 'Rwanda'), 
(189, 'Saint Helena'), 
(190, 'Saint Kitts and Nevis'), 
(191, 'Saint Lucia'), 
(192, 'Saint Pierre and Miquelon'), 
(193, 'Saint Vincent and The Grenadines'), 
(194, 'Samoa'), 
(195, 'San Marino'), 
(196, 'Sao Tome and Principe'), 
(197, 'Saudi Arabia'), 
(198, 'Senegal'), 
(199, 'Serbia and Montenegro'), 
(200, 'Seychelles'), 
(201, 'Sierra Leone'), 
(202, 'Singapore'), 
(203, 'Slovakia'), 
(204, 'Slovenia'), 
(205, 'Solomon Islands'), 
(206, 'Somalia'), 
(207, 'South Africa'), 
(208, 'South Georgia and The South Sandwich Islands'), 
(209, 'Spain'), 
(210, 'Sri Lanka'), 
(211, 'Sudan'), 
(212, 'Suriname'), 
(213, 'Svalbard and Jan Mayen'), 
(214, 'Swaziland'), 
(215, 'Sweden'), 
(216, 'Switzerland'), 
(217, 'Syria'), 
(218, 'Taiwan'), 
(219, 'Tajikistan'), 
(220, 'Tanzania, United Republic of'), 
(221, 'Thailand'), 
(222, 'Timor-leste'), 
(223, 'Togo'), 
(224, 'Tokelau'), 
(225, 'Tonga'), 
(226, 'Trinidad and Tobago'), 
(227, 'Tunisia'), 
(228, 'Turkey'), 
(229, 'Turkey'), 
(230, 'Turkmenistan'), 
(231, 'Turks and Caicos Islands'), 
(232, 'Tuvalu'), 
(233, 'Uganda'), 
(234, 'Ukraine'), 
(235, 'United Arab Emirates'), 
(236, 'United Kingdom'), 
(237, 'United States'), 
(238, 'United States Minor Outlying Islands'), 
(239, 'Uruguay'), 
(240, 'Uzbekistan'), 
(241, 'Vanuatu'), 
(242, 'Vatican City'), 
(243, 'Venezuela'), 
(244, 'Vietnam'), 
(245, 'Virgin Islands, British'), 
(246, 'Virgin Islands, U.S.'), 
(247, 'Wallis and Futuna'), 
(248, 'Western Sahara'), 
(249, 'Yemen'), 
(250, 'Yemen'), 
(251, 'Zambia'), 
(252, 'Zimbabwe'); 

下面的錯誤代碼是看到微軟SQL服務器 -

消息215,級別16,狀態1,行提供1個 參數對象'國家'這不是一個功能。如果參數用作表提示,則需要WITH關鍵字。

請分享幫助的原因吧?

回答

9

請勿爲列名使用單引號。

INSERT INTO Countries ([sno], [Name])... 

您可以正常使用括號。 或者,如果SET QUOTED_IDENTIFIER爲ON時,您可以使用雙引號"(它應該是默認的)

目前你有導致SQL Server來解釋代碼的方式,你希望

+1

謝謝@gbn的快速回復 – Tectrendz 2012-07-22 09:34:13

+5

其實我個人建議*從不*使用任何引號標識符(既不'''也不''''「)。如果需要它們,則意味着使用非標準名稱(保留字,特殊字符),從長遠來看這不是一個好主意。 – 2012-07-22 09:36:36

+2

INSERT INTO Countries(sno,Name).. – kinkajou 2012-07-22 09:36:45

1

你能有什麼不同的字符串文字保留所有括號內的部分了一起:SQL Fiddle

INSERT INTO Countries VALUES 

因此,這沒有明確的而不是最好的做法(見@AaronBertrand評論) - 但仍然是一個選擇。

+0

不推薦這種做法,主要是因爲它修復了查詢到表的當前狀態。如果我稍後添加,刪除或重新排列列,則此代碼會中斷。 – 2012-07-22 17:08:08