Showing posts with label raw. Show all posts
Showing posts with label raw. Show all posts

Friday, March 23, 2012

Importing related data

I need to recreate a SQL 2005 db in a SQL 2000 server. So far I was able to recreate database schema, but I don't know how to import the raw data. I tried copy-pasting table data to the new db using SQL Server Management Studio Express, but there's a problem - the identity columns do not retain the correct values. For example:

Old db table

ID Username
-
15 Peter
45 James

When pasting the same data to teh new db, I would get this:

ID Username

-

1 Peter

2 James

You can see the ID field values become different (since the ID attribute is an identity and the table in the new db is empty, the db picks the values 1 and 2 for the two records) and now when pasting data into related tables, I get the error because table relations (which are based on identities) do not match. How do I solve this problem and import all the data into the new db while maintaining correct relationships among tables?

Issue SET IDENTITY_INSERT <table-name> ON prior to loading the data! that enables you to load whatever values you like into there.

-Jamie

|||It probably works when running INSERT sentences, but I want to copy-paste data using SQL Server Management Studio Express.

Maybe there's a way to export the data into txt format by generate INSERTS?|||

Copying and pasting is not a method of moving data between tables.

Generating inserts is a very good idea. Do a search on the internet for sp_generate_inserts

-Jamie

Friday, February 24, 2012

Importing binary data tables?

My apologies in advance for hitting the forum with such a basic question...

I've got a large number of raw binary data tables generated by some external software that I'd like to import into a SQL database. I've set up the database tables to hold the information and assigned the table columns the appropriate data types, but I can't figure out how to import the data.

From what I can see there isn't a data import 'wizard' that supports raw binary, and my limited experience with bcp has given me the impression that it only supports ASCII tables. I find it hard to believe that there isn't a DTS procedure to handle this... but I'm definitely stuck...

Thanks,
-fpsivYou can import data by using bcp or bulk insert to text or image fields and then parse data if it needs.|||Thanks for the quick reply snail...

I was working with BULK INSERT via the Query Analyzer... but ran into a brick wall in trying to set up the format file. I can't seem to get the 'column collation' parameter set correctly. I thought that 'collation' applied to character data... is there a correct collation for raw binary?

Thanks,
-fpsiv|||Check this : import image, I was trying to the same for binary file - it works too.

http://www.dbforums.com/t926676.html|||Thanks snail... got it working! I really appreciate your help!

Cheers
-fpsiv|||hmmml ! I tried the same query but it didn't worked :

CREATE TABLE Pictures
(
Pic_id smallint
IDENTITY(1,1)
PRIMARY KEY CLUSTERED,
Images nvarchar(5000)
)

BULK INSERT Northwind.dbo.[pictures] FROM 'c:\bridge.jpg'
WITH (
FORMATFILE = 'c:\bcp.fmt'
)

------------
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'from'.

Did I missing something?

Thanks