CSV import in SQL - Add new updated existing - sql-server

Is there a way to use the existing Import features from SQL Server Manager, to import a CSV file and if the record (by primary key)exists update record and if it doesnt exist then insert or do i have to write custom scripts to do this?

You will have to write something custom for this. The import wizard cannot do this.

Related

How to generate Insert statement from PGAdmin4 Tool?

We are writing a new application, and while testing, we will need a bunch of dummy data. I've added that data by using MS Access to dump excel files into the relevant tables into the Postgres database.
What should I do now to generate an Insert statements from the PGAdmin4 Tool similar to what SQL Studio allow us to generate an Insert statements for SQL Server? There are no options available to me. I can't use the closest one, which is to export and import the data via CSV.
I understand that you cannot import the CSV file into the actual DB as this needs to be done through ASP.NET core EF. Perhaps, you can probably create a test schema and import the CSV file into the test schema. Once you have the data imported into the test schema, you can use that to generate SQL statements using the steps below:
Right click on target table and select "Backup".
Select a file path to store the backup. You can save the file name as data.backup
Choose "Plain" as Format.
Open the tab "Options" check "Use Column Inserts".
Click the Backup-button.
Once the file gets generated you can open with Notepad++ or VSCode to get the SQL insert statements
You can use the statements generated and delete the test schema created
Here is a resource that might help you in loading data from Excel file into PostgresSQL if you still need to take this path Transfer Data from Excel to PostgreSQL

Script to import text files to SQL Server

I have around 1000 text files that need to be imported as tables to MS SQL Server. Usually I use Import and Export Data Tool, but doing that a 1000 times would be insufficient.
Is there a way to automate the process and import the 1000 text files and create the tables in SQL without doing that manually? Can that be achieved using a script?
Use SSIS. Start with your export package saved to the file system. In SSDT create a new SSIS project. Delete the Package.dtsx file created with the project. Right click the Packages "folder" and select Add Existing Package, navigate to the package you saved and select it. Now you can start automating the loads.

Import flat file into SQL Server

I'm trying to import a flat file into SQL Server and I'm having some issues. The column delimiter is ;~ and the row delimiter is |~. I'm using the SQL Server Import and Export Wizard but keep getting errors. Have any of you every had a similar issue? I think I'm doing it wrong from the start of the wizard. Can any of you talk me through the steps. Thanks.
Here is the import error:
It's a familiar-sounding problem, but difficult to be sure without a data file to play with - perhaps one of these posts has your answer:
Text was truncated or one or more characters had no match in the target code page including the primary key in an unpivot
Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column
SQL Server Import wizard fails with incomprehensible message
Thanks to all of you who responded.
My solution was to first create the tables in SQL Server using the varchar(max) data type for each column and then executing a BULK INSERT statement. Definitely not ideal, but the goal was not to create a database but rather delimit the data so I could upload it to an application. Thanks again.

Importing a CSV file without headers into SQL 2008

I want to import a CSV with 4,8M records into a SQL 2008 table. I'm trying to do it with the Management Studio wizard but it keeps trying to recognize a header row which the CSV doesnt have. I don't find any option to skip this and although I specify the columns myself, the wizard still tries to find a header row and doesnt import anything without it.
The structure of the CSV is
"818180","25529","Dario","Pereyra","Rosario","SF","2010-09-02"
I've also tried alternatives like BULK INSERT but then I find out that with BULK INSERT I can't import files with a text qualifier.
The easiest way for a one time import would definitely be the "Import Data" function in SQL Server Management Studio. This will launch a wizard and will allow you to define where you want to import your data from - pick "Flat File Source". The next dialog allows you to browse for the file you want to import, and you can specify all sorts of things on that dialog (like the encoding of the file, what the text qualifier is - if any - and so on.
You can also select to skip any number of rows (e.g. "skip the first 5 rows"), or you can select that the first row has column names.
If your file does not have the column names in the first row, uncheck that option.
If you need to do this import over and over again, you can save all the information about the import as a Integration Services package in SQL Server (or in an external SSIS file), and you can then run that import again and again from the SQL Server Agent "Jobs" menu (enable SQL Server Agent, if you haven't already, and find the "Jobs" sub-item - you should see all your jobs under there and you can launch them again from that menu).
And if you want to, you can also launch these SSIS packages from your C# or VB.NET code - check out this CodeProject article or see Michael Entin's blog post on the topic.
Uncheck "first row has column names"
http://epicenter.geobytes.com/images/MsSqlI006.gif

SQL Server: how to export a table

how can I export a SQL Server table to Mysql ? I guess I need to export a .sql file compatible...
thanks
Solution: Right Click on database Icon > Tasks > Generate Scripts
follow istructions and export a specific table as .cvs
One way is to BCP the data out into a CSV or some other format flat file and import those into mySQL.
Another way is to use a SSMS add-in called SSMS Tools Pack which has the option to generate insert statements.
please see the below link, maybe it can help you.
MSSQL to MySQL

Resources