I am using ODBC and FreeTDS to connect from a linux server to an MS SQL Server 2008 (connection string). I need to get the contents of a local .CSV file on the RHEL-server in a table on the SQL server. However my SQL is a little shabby to say the least. How should I proceed? I am a stranger to DBI as well.
#!/usr/bin/perl
# PERL MODULES WE WILL BE USING
use DBI;
use DBD::ODBC;
my $data_source = q/dbi:ODBC:MSSQLServer/; # DSN string from /etc/odbc.ini
my $user = q/Username/;
my $password = q/Password/;
my $dbh = DBI->connect($data_source, $user, $password, {RaiseError => 0, PrintError => 1}) or die "Can't connect to $data_source: $DBI::errstr";
The .csv file contains 2 values separated by commas on each line. Every line must be inserted in the table. The table on the database has 2 columns (attribute1
and attribute2
).
.csv content example:
server1, id1
server2, id2
server3, id1
server4, id9
Primary key is number value already set so I don't think duplicate values are an issue.