你是Litware,Inc的数据库开发者。你正在修改该公司的sales数据库结构。该
INSERT INTO Country (CountryName)SELECT DISTINCT CountryFROM Customers
SELECT (*) AS ColID, c1.CountryINTO CountryFROM (SELECT DISTINCT Country FROM Customers)AS c1,(SELECT DISTINCT Country FROM Customers) AS c2,WHERE c1.Country >=c2.CountryGROUP BY c1.Country ORDER BY 1
DECLARE @Country char (20)DECLARE cursor_country CURSORFOR SELECT Country FROM CustomersOPEN cursor_countryFETCH NEXT FROM cursor_country INTO @CountryWHILE (@@FETCH_STATUS <> -1)BEGINIf NOT EXISTS (SELECT CountryIDFROM CountryWHERE CountryName = @Country)INSERT INTO Country (CountryName) VALUES (@Country)FETCH NEXT FROM cursor_country INTO @CountryENDCLOSE cursor_countryDEALLOCATE cursor_country
DECLARE @SQL varchar (225)SELECT @SQL = ‘bcp “SELECT ColID = COUNT(*), c1. Country’ +‘FROM (SELECT DISTINCT Country FROM Sales..Customers) ASc1, ' +(SELECT DISTINCT Country FROM Sales..Customers) AS c2 '+WHERE c1.Country >= c2.Country’ +‘GROUP BY c1.Country ORDER BY 1’ +‘query out c:\country.txt -c’EXEC master..xp_cmdshell @SQL, no_outputEXEC master..xp_cmdshell ‘bcp Sales..Country in c:\country. Txt-c’, no_output
参考答案: