Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Programming / SQL / July 2008

Tip: Looking for answers? Try searching our database.

Relations among tables in different DBs??

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed White - 23 Jul 2008 21:04 GMT
If I have two different data bases on the same server, is it possible to
create a relationship between fields in tables between the two different DBs?
Signature

Ed

Aaron Bertrand [SQL Server MVP] - 23 Jul 2008 21:08 GMT
No, you need to enforce this in other ways... triggers being the typical
workaround.  However note that this is not always as reliable as single-DB
RI, and requires extra planning in a restore scenario (or any other downtime
for one but not the other).

On 7/23/08 4:04 PM, in article
91C89876-4998-47AC-AD89-0FF774AD76C9@microsoft.com, "Ed White"
<ewhite@newsgroups.nospam> wrote:

> If I have two different data bases on the same server, is it possible to
> create a relationship between fields in tables between the two different DBs?
Ed White - 23 Jul 2008 21:19 GMT
As I thought.

Basically, I have some archive data I'd like to store, but I don't want to
store in the the main DB as it will make the DB larger and therefore make it
take longer to backup.  Thus, I thought I'd store the archive data in another
DB which would be backup up less frequently, but I need to maintain some
cascading update relationships to keep the data consistent.

I know there is a way to split files in a DB, but I've heard this is very
cumbersome.
Signature

Ed

> No, you need to enforce this in other ways... triggers being the typical
> workaround.  However note that this is not always as reliable as single-DB
[quoted text clipped - 7 lines]
> > If I have two different data bases on the same server, is it possible to
> > create a relationship between fields in tables between the two different DBs?
Alex Kuznetsov - 23 Jul 2008 21:53 GMT
> As I thought.
>
[quoted text clipped - 6 lines]
> I know there is a way to split files in a DB, but I've heard this is very
> cumbersome.

this might cause you more problems than solve. Can you try out the
following:

--Backing up specific files or filegroups
BACKUP DATABASE { database_name | @database_name_var }
    <file_or_filegroup> [ ,...f ]
TO <backup_device> [ ,...n ]
[ [ MIRROR TO <backup_device> [ ,...n ] ] [ ...next-mirror ] ]
[ WITH
    [ BLOCKSIZE = { blocksize | @blocksize_variable } ]
    [ [ , ] { CHECKSUM | NO_CHECKSUM } ]
    [ [ , ] { STOP_ON_ERROR | CONTINUE_AFTER_ERROR } ]
    [ [ , ] DESCRIPTION = { 'text' | @text_variable } ]
    [ [ , ] DIFFERENTIAL ]
    [ [ , ] EXPIREDATE = { date | @date_var }
   | RETAINDAYS = { days | @days_var } ]
    [ [ , ] PASSWORD = { password | @password_variable } ]
    [ [ , ] { FORMAT | NOFORMAT } ]
    [ [ , ] { INIT | NOINIT } ]
    [ [ , ] { NOSKIP | SKIP } ]
    [ [ , ] MEDIADESCRIPTION = { 'text' | @text_variable } ]
    [ [ , ] MEDIANAME = { media_name | @media_name_variable } ]
    [ [ , ] MEDIAPASSWORD = { mediapassword |
@mediapassword_variable } ]
    [ [ , ] NAME = { backup_set_name | @backup_set_name_var } ]
    [ [ , ] { NOREWIND | REWIND } ]
    [ [ , ] { NOUNLOAD | UNLOAD } ]
    [ [ , ] RESTART ]
    [ [ , ] STATS [ = percentage ] ]
    [ [ , ] COPY_ONLY ]
]
Ed White - 23 Jul 2008 22:27 GMT
I'm not sure what you are suggesting, Alex.  I use the BACKUP command to
backup my DB already.  What would be handy is if I could backup e.g. all but
one specific table in the DB.  The one table not backed up would be the
archive table which is updated less frequently than the rest of the DB.  It
appears the entire DB is stored in one file, unless, as I suggested earlier,
you split it into several files, but I hear that often creates more problems
than it solves.
Signature

Ed

> > As I thought.
> >
[quoted text clipped - 38 lines]
>      [ [ , ] COPY_ONLY ]
> ]
Alex Kuznetsov - 23 Jul 2008 22:34 GMT
> I'm not sure what you are suggesting, Alex.  I use the BACKUP command to
> backup my DB already.  What would be handy is if I could backup e.g. all but
[quoted text clipped - 48 lines]
> >      [ [ , ] COPY_ONLY ]
> > ]

I'm suggesting that you partition your table and/or back up specific
files or filegroups. This is the built in way of dealing with such
problems. Whatever you have heard, try it out anyway and see for
yourself if it solves your problems. The homemade alternative you are
trying to come up with might be much more complex. A canned answer:

http://sqlblog.com/blogs/alexander_kuznetsov/archive/2008/05/13/be-aware-of-thes
e-loopholes-in-your-referential-integrity.aspx

Tibor Karaszi - 24 Jul 2008 08:02 GMT
It seems you want to both eat the cake and have it. You say (1) that you want RI. But you also want
different backup schedules.

What if one of the databases crashes and you for that one need to restore from a backup which is 1
hours old? RI is lost.

Or what if the server crashes and you need to restore both databases. But the backups are from
different point in time (could be only seconds apart - but still). RI is lost.

What Ales suggests is that you work at the filegroup level. SQL Server will never restore a
databases from different point in times. But that also mean that you for such a backup scenario do
your due diligence.

Signature

Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi

> I'm not sure what you are suggesting, Alex.  I use the BACKUP command to
> backup my DB already.  What would be handy is if I could backup e.g. all but
[quoted text clipped - 46 lines]
>>      [ [ , ] COPY_ONLY ]
>> ]
Eric Russell - 23 Jul 2008 23:30 GMT
Using triggers, I insert modified table rows to another database for the
purpose of auditing and data versioning. However, I don't attempt to maintain
referential integrity or cascading deletes / updates back to them, becuase
that would defeat the purpose of auditing.
Are you perhaps wanting to partition specific tables, that is move related
data for inactive orders or patients to another database for performance
reasons? Once done, you would like updates or deletes to the base tables to
carry over to the archived partition? Perhaps [distributed partitioned views]
would fit your need. It is basically a view that unionizes two or more
tables, which could span multiple databases or even servers. Rather than
reference the partitioned tables directly, you instead select from and update
the view, and SQL Server's execution plan figures out which table to
reference based on what value is contained in a designated partition column.
It will even transparently implement a delete/insert for a row when you
update it's partition column. This works with v2000+
http://www.fotia.co.uk/fotia/FA.02.Sql2KPartitionedViews.01.aspx#IntroducingPart
itionedViews


Beginning with SQL Server 2005, you can implement [table partitioning]. This
is a similar concept, which is a bit more difficult to implement, because it
involves altering the schema of your tables and enforcing some somewhat
strict rules, but it is easier to manage once setup, because you are dealing
with one physical table. You can still enforce referential constraints like
usual, however, unlike [partitioned views], it cannot span multiple databases
or servers, just multiple file groups.
http://www.mssqltips.com/tip.asp?tip=1200

> As I thought.
>
[quoted text clipped - 18 lines]
> > > If I have two different data bases on the same server, is it possible to
> > > create a relationship between fields in tables between the two different DBs?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.