在Microsoft SQL Server Management Studio中插入整个表

时间:2013-04-27 13:58:11

标签: sql sql-server

基本上我有一份来自Google的92种货币(ID和名称)列表:

https://developers.google.com/adsense/management/appendix/currencies

我可以将所有数据一次性插入Microsoft SQL Server吗?

4 个答案:

答案 0 :(得分:2)

您可以使用Management Studio中的“导入/导出”向导从csv获取数据。只需右键单击您的数据库,选择任务 - >导入数据并按照向导,这很简单。

这是一个链接提供教程: http://www.mssqltips.com/sqlservertutorial/203/simple-way-to-import-data-into-sql-server/

答案 1 :(得分:2)

只需下载.csv文件并删除第一行即列标题并运行即可 以下代码。将.csv文件保存在C盘中。

create TABLE Currencies
(
CurrecyCode nchar(5),
CurrencyName nvarchar(30)
)

BULK
INSERT Currencies
FROM 'c:\currencies.csv'
WITH
(
CODEPAGE='RAW',
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO

答案 2 :(得分:1)

由于您只使用了几行,编辑器中的几分钟就可以生成SQL状态。

INSERT INTO MyTable(ID,  Name)
VALUES
('AED', 'United Arab Emirates Dirham'),
('ARS', 'Argentine Peso'),
('AUD', 'Australian Dollar'),
('BGN', 'Bulgarian Lev'),
('BND', 'Brunei Dollar'),
('BOB', 'Bolivian Boliviano'),
('BRL', 'Brazilian Real'),
('CAD', 'Canadian Dollar'),
('CHF', 'Swiss Franc'),
('CLP', 'Chilean Peso'),
('CNY', 'Chinese Yuan Renminbi'),
('COP', 'Colombian Peso'),
('CZK', 'Czech Republic Koruna'),
('DKK', 'Danish Krone'),
('EGP', 'Egyptian Pound'),
('EUR', 'Euro'),
('FJD', 'Fijian Dollar'),
('GBP', 'British Pound Sterling'),
('HKD', 'Hong Kong Dollar'),
('HRK', 'Croatian Kuna'),
('HUF', 'Hungarian Forint'),
('IDR', 'Indonesian Rupiah'),
('ILS', 'Israeli New Sheqel'),
('INR', 'Indian Rupee'),
('JPY', 'Japanese Yen'),
('KES', 'Kenyan Shilling'),
('KRW', 'South Korean Won'),
('LTL', 'Lithuanian Litas'),
('MAD', 'Moroccan Dirham'),
('MXN', 'Mexican Peso'),
('MYR', 'Malaysian Ringgit'),
('NOK', 'Norwegian Krone'),
('NZD', 'New Zealand Dollar'),
('PEN', 'Peruvian Nuevo Sol'),
('PHP', 'Philippine Peso'),
('PKR', 'Pakistani Rupee'),
('PLN', 'Polish Zloty'),
('RON', 'Romanian Leu'),
('RSD', 'Serbian Dinar'),
('RUB', 'Russian Ruble'),
('SAR', 'Saudi Riyal'),
('SEK', 'Swedish Krona'),
('SGD', 'Singapore Dollar'),
('THB', 'Thai Baht'),
('TRY', 'Turkish Lira'),
('TWD', 'New Taiwan Dollar'),
('UAH', 'Ukrainian Hryvnia'),
('USD', 'US Dollar'),
('VEF', 'Venezuelan Bolí­var Fuerte'),
('VND', 'Vietnamese Dong'),
('ZAR', 'South African Rand')

如果您使用SSMS中的Alt + select(columnar select)进行复制和粘贴,则可以选择文本列以轻松添加引号。

编辑:我以为我会花一点时间在记事本中做这件事

答案 3 :(得分:0)

您可以使用一堆方法获取CSV并将其导入SQL Server。

  1. Using Bulk Insert
  2. Using BCP
  3. Using SSIS