Loading .csv File into SQL Server using SSIS Technique - ssis

I am new to SQL Server and SSIS. I want to shedule the loading of .csv file into SQL Server.I want to run the loading for a specific time daily.Please help.Thanks in Advance.

You can do this by first creat the table(s) in SQL with the appropriate data types. Then by importing into SQL first and then write your script to update the table but a .bat file would require in order to run your scripts. The following is an example command for a .bat file: sqlcmd -S ServerName -U UserName P Password -i "C:\folder\update.sql"-o "C:\folder\output.txt"
You will need to write the .csv file to a text file and change the extension to .sql
You can use the "Bulk Insert Command"
Example:
BULK INSERT FILENAME
DATABASENAME.DBO.TABLENAME
FROM 'C:\sqlscript\fileName.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
Hope this helps

Related

Add csv in cassandra

How can I add .csv files from my local storage to Cassandra(running on AWS server) using puTTY.
I am trying this but it gives me an error saying "cant open. No matching path found" (even though the file is present in that location)
copy tableName (col1, col2,col3) from 'C:\Users\TEST.csv' with HEADER = true ;
The .csv file first has to be on an FTP application(example FileZilla) before uploading it to Cassandra while using puTTY.

Load data infile MySQL with absolute URL

i trying load a CSV in a table.
I have my CSV in a folder of my server. (wwww.myweb.com/temp/file.csv)
I use this sentence:
LOAD DATA INFILE 'http://wwww.myweb.com/temp/file.csv' INTO TABLE ga_tmpActivosDocumentos FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n' IGNORE 1 LINES (idTipoSuelo,C_Latitud,C_Longitud,Referencia,Zona,idProvincia,Poblacion,TituloActivo,Descripcion,Superficie,Gastos,Equipamiento,EquipamientoEN,GestionDocumental,PrecioVenta,CampoLibre1_Texto,CampoLibre1_Titulo,CampoLibre1_TextoEN,CampoLibre1_TituloEN,Activo, IMG1,IMG_Desc1,IMG_Desc1EN,IMG2,IMG_Desc2,IMG_Desc2EN,IMG3,IMG_Desc3,IMG_Desc3EN,IMG4,IMG_Desc4,IMG_Desc4EN,DOC1,DOC_Desc1,DOC_Desc1EN,DOC2,DOC_Desc2,DOC_Desc2EN,DOC3,DOC_Desc3,DOC_Desc3EN,DOC4,DOC_Desc4,DOC_Desc4EN,URL1,URL_Desc1,URL_Desc1EN,URL2,URL_Desc2,URL_Desc2EN) SET idCliente = 23
The sentence not work for me. I try to change the path to .../temp/file.csv, and other combinations but not work.
Also use "LOAD DATA LOCAL INFILE" but does not work.
I have read other topics, but only look examples with a relative URL, never absolute.
Thanks, and sorry for my english
#vadym-tyemirov answer works but if you don't want to create a temporary file, one solution is to load it from '/dev/stdin' and pipe it to the mysql cli:
wget -O - 'http://wwww.myweb.com/temp/file.csv' |
mysql \
--user=root \
--password=password \
--execute="LOAD DATA LOCAL INFILE '/dev/stdin' INTO TABLE table_name"
Save CSV file on your LOCAL computer.
Connect to the DB from your LOCAL computer
Issue the following command: load data LOCAL infile '/tmp/file.csv' INTO TABLE table_name;
You can also load data files by using the mysqlimport utility; it operates by sending a LOAD DATA INFILE statement to the server. The --local option causes mysqlimport to read data files from the client host.
MySQL cannot access the file in that location. Try moving it somewhere simple like /tmp (or copy it) on the local filesystem, and not via a URL parameter.
The MySQL process likely cannot load the folders BEFORE "temp/file.csv"

how to run .sql file from SSMS?

Hi i am using SQL SERVER 2008 R2 and i wanted to execute prestored *.sql files in a folder and wanted to run in SSMS.
can it be possible and if possible can somebody please help me to get how can we implement that?
Ok If I'm clear with your question.
Go to cmd and navigate to the path where you have stored your .sql file.
In my case I've stored file on desktop with vish.sql name.
then sqlcmd -S DALVI1 -d cookbookdb -i vish.sql
Note (This is my configuration
DALVI1 is my ServerName
cookbookdb is database name
vish.sql is filename)
Modify as per your configuration.
For More Reference

MySQL load command: is there a wildcard available for the datafile?

I have the following file dumped daily into one of our online directories:
dat-part2-489359-43535-toward.txt
The numbers change each day randomly.
I have the following code to try and LOAD the file:
mysql_query("LOAD DATA LOCAL INFILE 'dat-part2-%-toward.txt'
REPLACE INTO TABLE my_table
FIELDS TERMINATED BY ',' ENCLOSED BY ''
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES") or die(mysql_error());
And of course no luck. What's the best way to do this?
assuming this is a scheduled job, why not check the directory for the most recent file that matches your filename template. Store the name of said file in a variable and then sub the variable into your query. Check out glob()
I would do it via a shell script or windows cmd file. This assumes you created the file with mysqldump or some program that creates a valid sql script.
You can run dir /B in windows commend to get a directory of files. So do a dir /B > input.txt then use Windows scripting to read the input file and for each line, pipe the file in using the mysql client.
# echo off set infile= %%1
for /f "eol= tokens=*
delims= usebackq" %%i in (%infile%)
do ( mysql -u userName --password=pwd < %%i )
It's been a long time since I wrote any windows scripts, but that should give you an idea of an approach.

Loading MySQL dump file with bin extension

I know how to restore MySQL DB with *.sql files.
But i don't know how to import *.bin files. Content in this file is:
123456789|www.site-name.com
123789456|www.go.com
123987456|www.g1.net
987865432|www.site.org
Please help!
*.bin files are mysql logs. You can view these files with the command mysqlbinlog
http://dev.mysql.com/doc/refman/5.0/en/mysqlbinlog.html
BUT looking at the content of the file, it appears to be just plain text file with | as a column separator. (The default column separator in mysql is TAB.)
You can load file with the following command
LOAD DATA INFILE '/path/to/file.bin'
INTO TABLE table_name
FIELDS TERMINATED BY '|'
http://dev.mysql.com/doc/refman/5.0/en/load-data.html