You are on page 1of 1

** Crear la tabla

CREATE TABLE CSVTest


(ID INT,
FirstName VARCHAR(40),
LastName VARCHAR(40),
BirthDate SMALLDATETIME)
GO
** Insertar datos desde un archivo delimitado por comas
BULK INSERT CSVTest
FROM 'c:\csvtest.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
** Revisar los datos insertados
SELECT *
FROM CSVTest
GO
*** Exportar datos a un archivo de texto delimitado por comas
SELECT * FROM EmployeeMaster
INTO OUTFILE C:/testing.csv
FIELDS ENCLOSED BY TERMINATED BY ; ESCAPED BY
LINES TERMINATED BY \r\n';
** configurar
SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshe
ll' because this component is turned off as part of the security configuration f
or this server. A system administrator can enable the use of 'xp_cmdshell' by us
ing sp_configure. For more information about enabling 'xp_cmdshell', see "Surfac
e Area Configuration" in SQL Server Books Online.

USE master
GO
EXECUTE sp_configure 'show advanced options', 1
RECONFIGURE WITH OVERRIDE
GO
EXECUTE sp_configure 'xp_cmdshell', '1'
RECONFIGURE WITH OVERRIDE
GO
EXECUTE sp_configure 'show advanced options', 0
RECONFIGURE WITH OVERRIDE
GO
Para usar
EXEC xp_cmdshell 'bcp "SELECT * FROM CSVTest" queryout "C:\bcptest.txt" -T -c -t
,'
go

You might also like