Importing a CSV file into VS 2015 Database - sql-server

I have a SQL Server Database as a project. I created it using Add Item -> SQL Server.
On the database project I do Add Item > Table which adds an SQL file. That sql file just creates a table with column Id, nothing else.
I then published that database. I can now see it on the Server Object Explorer.
I want to populate the table using a CSV file, and I also want to import the columns from the CSV file.
Then I created a new Query in the Object Explorer and used a BULK INSERT statement to import the csv file. I wanted to see if it would work because the table has just an Id column, and it did not. So my question is, how do I import the new columns when the table already has it's own schema?
I have also used the SQL Import and Export Wizard which is packaged with Microsoft SQL Server 2016. That is able to create a new table, but not import the new columns into a previously existing table.

You can find the explanation of how to do this in 1 operation here:
How to create and populate a table in a single step as part of a CSV import operation?

Related

Importing data from Excel into a Linked SQL Server Table in MS Access

I am attempting to import a large Excel file into Access, into a linked table connected to SQL Server. When I left click on the linked table in Access, and select "import", I'm shown three options. Whatever option I select, it seems to create a new local table with the same name, rather than importing the Excel data into the SQL Server table that is linked. Does anyone know what I can do? Basically I'd like to use Access to access a SQL Server table, and be able to paste or import a large amount of data from Excel to the linked table in Access.
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml,"dbo.Yourtablename","your file path and name with extension",true (only if the excel file has field names that match your table field names),choose your excel cell range (example: A2:A324)

SQL Import data from Azure using SSMS Import/Export Wizard

I have created a local database and now I am trying to import data from my azure database using SSMS Import/Export wizard. It worked fine and data is imported. The issue is the primary key is auto-generated during the import process and is different from the remote database due to which I am facing some issues when I try to run my code. For example. I have two tables Customers and Products. The Primary key ID in my remote customer table starts from 5. So, the id of the second customer is 6. But now since the second customer's ID is 2 in my local DB and my foreign key is still 6 in the Product table. It points to a different customer now. Is there a way to import data as it is from remote DB, even the primary key or is there another way to do this.
Thanks in advance.
You can use this tool, it may help you to import the data successfully
https://sqlazuremw.codeplex.com/
In SQL Server Import and Export Wizard, after Copy data from on or more tables or views, you select source tables, OPEN Edit Mapping... check Enable identity insert.
I understood that I wanted the exact copy of the database and this cannot be achieved using the Import/Export wizard as it generates the Primary keys during the import process. The database becomes unusable if you have deleted some rows on the server etc. In this case, I created a bacpac file using the SqlBackupandftp tool. Then, created the database locally using the bacpac file. [SSMS -> right click on the Databases folder -> Import Data-Tier application -> Choose the bacpac file. This will copy the database as such.

how to import excel to sql server 2008?

We have an excel file more than 500 columns. And we have to import this file into MS SQL SERVER 2008 table. But it only accepts 255 columns.
Can anyone suggest a way to import/copy excel data to sql table ?
please go through below link and follow the steps
https://www.mssqltips.com/sqlservertutorial/203/simple-way-to-import-data-into-sql-server/
While using the Import wizard, Click on Edit Mappings on the "Select Source Tables and Views" page of the wizard, check the Type, Nullable, and Size columns for each source column. And must and should mapping should be done properly
Did you try bulk Insertion?
You can able to move excel data into SQL Server using bulk insert command below.
BULK INSERT table_name FROM 'C:\Directory\excelfile.csv' WITH (FIELDTERMINATOR='\t',ROWTERMINATOR='\n', ROWS_PER_BATCH=10000)

Importing a .csv files into sql server 2014 database

I am trying to import a .csv files into my sql Database that has been created on the SQL server 2014. The problem is that my csv tables have different names from the tables that I have create in my own Database. I cannot change the names on the csv files or the names on my database. They have to stay as they are. Can import the csv files into each table on my database without having an error? please help me out, i'm confused.
Use the import export wizard that is packaged with SQL Server, you can set the data source to a flat file such as CSV. It has a built in mapping option as below
I assume you are using import wizard, but once you pick data source and data destination, go to option "edit Mappings", there you can check which columns goes where, just make sure that columns are the same type
Yes, Steps:
Select the database
Right Click and Select the task and click on export
Select the source database and click next and select the CSV database as destination
click next and do the mapping of Source and destination columns
Click next to Finish
Now data will be imported to the database on appropriate columns

Using sql importer, how can I import schema details like PK/FK?

I did a sql import (sql08) and it didn't import PK/FK type information.
It only transfered data and created the tables.
How can I make it do this?
SCript the tables including scripting indexes, constraints, foreign keys etc.
Run the script then use the wizard to transfer the data into the new empty table using append rather thant create.
You could also using the wizard click on Edit mappings (onthe Select Source Tables and Views page) and then edit SQl and add the code for those things yourself to the table definition script.

Resources