Import SQL records from file into sql DB and changing type - sql

I created a .txt file using BULK that contains all the records of a sql DB. Now I need to import these records into a new DB. The problem is that I need to change the type of some fields from DOUBLE to BIGINT or the records won't be added to the new DB.
Please, wich functions and how do I have to use them?
Thanks

Importing into SQL Server, you can right-click on the database and select Tasks > Import Data. This will open up the Import/Export Wizard which is a slimmed down version of the same functionality in SSIS.
Once the Wizard is open, you can navigate the through the prompts and eventually get to a screen, Select Source Data, where you can click on the Edit Mappings button and modify the data types of the data being imported.

Related

SQL Server Data Import / Export Wizard Truncation Error

I'm trying to load a large file into a SQL Server table. I know that two of the columns are > 50 characters wide so on the 'Advanced' tab in the Import/Export Wizard, I specify the width as 115 and 75 respectively. I then run the rest of the job and get the following error:
Is there another place I need to let the Wizard know about the change in length?
Check your database. There is a chance that the table was created from your previous unsuccessful wizard run. It is recommended to delete the table and wizard should re-run successfully without warnings.
Try letting the import wizard create the new table for you. Then you can use regular SQL to move it to its permanent table.

How can I carry a database created in dbDesigner to SQL Server

I created a small database in dbDesigner which includes 4 tables, and I want to add these tables with their relationships to a database on a SQL Server. How can I do this?
Best practice for this that I am aware of, is using Management Studio's functionality for this.
The following steps will produce a file containing an SQL script you can run on any server you want in order to import the schema (with or without the data).
Right click on you database.
Select Tasks > Generate scripts
Click Next
Choose Script entire database and all database objects
Select Save to file and Single file
If you want to export data as well, click on Advanced and change Types of data to script to Schema and data (default is schema only)
Click Next ... Next.
Run the generated file on the server you want to import the schema to.

How to import pipe delimited text file data to SQLServer table

I have database table represented as text file in the following pattern:
0|ALGERIA|0| haggle. carefully f|
1|ARGENTINA|1|al foxes promise|
2|BRAZIL|1|y alongside of the pendal |
3|CANADA|1|eas hang ironic, silent packages. |
I need to import this data to a SQL Server 2008 database table. I have created the table with the types matching the schema.
How to import this data to the table?
EDIT: Solved by following the answer selected.
Note to anyone stumbling upon this in future: The datatype needs to be converted.
Refer: http://social.msdn.microsoft.com/Forums/en/sqlintegrationservices/thread/94399ff2-616c-44d5-972d-ca8623c8014e
You could use the Import Data feature by right mouse clicking the database, and then clicking Tasks then Import Data. This will give you a wizard which you can specify the delimiters etc. for your file and preview the output before you've inserted any data.
If you have a large amount of data you can use bcp to bulk import from file: http://msdn.microsoft.com/en-us/library/ms162802.aspx
The bcp utility bulk copies data
between an instance of Microsoft SQL
Server and a data file in a
user-specified format. The bcp utility
can be used to import large numbers of
new rows into SQL Server tables...
Except when used with the
queryout option, the utility requires
no knowledge of Transact-SQL. To
import data into a table, you must
either use a format file created for
that table or understand the structure
of the table and the types of data
that are valid for its columns.

BCP utility to create a format file, to import Excel data to SQL Server 2008 for BULK insertion

Am trying to import Excel 2003 data into SQL table for SQL Server 2008.
Tried to add a linked server but have met with little success.
Now am trying to check if there's a way to use the BCP utility to do a BULK insert or BULK operation with OPENROWSET, using a format file to get the Excel mapping.
First of all, how can I create a format file for a table, that has differently named columns than the Excel spreadsheet colums?
Next, how to use this format file to import data from say a file at: C:\Folder1\Excel1.xsl
into table Table1 ?
Thank you.
There's some examples here that demonstrate what the data file should look like (csv) and what the format file should look like. Unless you need to do this lots I'd just hand-craft the format file, save the excel data to csv, then try using bcp or OPENROWSET.
The format file specifies the column names for the destination. The data file doesn't have column headings so you don't need to worry about the excel (source) cols being different.
If you need to do more mapping etc, then create an SSIS package. You can use the data import wizard to get you started, then save as SSIS package, then edit to your heart's content.
If it's a one-off I'd use the SQL data import size, from right-click on database in mgmt studio. If you just have a few rows to import from excel I typically open a query to Edit Top 200 rows, edit the query to match the columns I have in excel, then copy and paste the rows from excel into SQL mgmt studio. Doesn't handle errors very well, but quick.

Import selected columns from a CSV files to SQL Server table

I am trying to import data from a CSV file to a SQL Server 2008 table. Data upload is working, but I want to import only selected columns, not all, and add them to a a new table, of same no. of columns, using the wizard, but its not happening, the wizard is selecting all the columns.
So is it possible using wizard that I only import selected columns.
If you are using the Import / Export wizard, when you get to Select Source Tables and Views click on the button "Edit Mappings" on the bottom left of the screen. That opens column mappings screen; on the destination column select Ignore to remove the column you don't want to import.
Since most people searching this question in 2019 aren't going to be using SQL2008, I'll add this for SQL Server 2016:
When you choose your Flat File data source, there is an Advanced option to the left of the window. Click that.
You will see a list of field names, and just below that there are 3 buttons. One of them is Delete.
Highlight the field you do not want to include and click the Delete button. Do this for all fields you do not wish to import.
First Use same data type which declare in choose data source file. After choosing "destination file" go to edit mapping, and select "edit sql" and take only selected column and declare the same data type. edit mapping select Ignore which column you don't want and declare same data type.