Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to Import a DB with Calculated Fields

Author  Topic 

coreysan
Starting Member

13 Posts

Posted - 2010-09-22 : 18:02:43
I've inherited a database with tables that have both hard data, and
calculated fields. For example, one table looks something like this:

create table mytable(
[Transaction] [tinyint] NULL,
[Batch] AS ([dbo].[DefaultUser]([ReferenceNo]))
);

How can I export/import into a new database where the table definitions would be identical, but I need the calculated data imported as well. I tried a small test, and using bcp it just imported the hard data, but the calculated fields were null. I already had all the various sprocs/functions in place when I performed the import, so I'm curious if I can actually create a new database, all things being equal.
Thanks for any response!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-09-22 : 18:11:16
Can you use backup/restore or is there "other" stuff in the new database that you need?

You could alternatively bcp into a staging table, and then use insert into/select from the staging table into the actual table in order to get the calculated data in there. I guess bcp must ignore the calculated functions.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -