Friday, March 23, 2012
relating tables from different databases
I am trying to relate two tables but both are from different databases. I have a database 'Current' which has a table 'case' and another database 'Org' which has a table 'employee'. I want to establish a one-to-many relationship between employee and case. I created a coulmn 'employee_key' in the case table & entered values matching the pkey of the employee table. Then I wrote a query using joins to access the table records.
select Org..employee.pkey, Current..case.assignedengineer, Current..case.pkey from Current..case join Org..employee on Current..request.employee_key=Org..employee.pkey
Although the above query works fine, there is no relation between the two tables of the two databases, I wanted to know if this is the right way to achieve what i want to or is there a way in which i can actually create a relationship between tables of two different datbases. Can anyone suggest/help?
Also, I wanted to know if i can relate 1 table of SQL Server db with another table of Oracle DB. Please help .........
Thankssql server does not support RI between databases out of the box. You could enforce it yourself using triggers however. there are also 3rd party products that do it for you:
http://www.remote-keys.com/
I have not used this product however, I just ran across it the other day.
EDIT: maybe you can be a beta tester for it: http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.sqlserver.server&tid=28c33f5c-8ae1-4f67-975a-3d002fd4d8e3&p=1sql
relate two tables based on an 'active' column
So I have a question and I will give a related example. Say I have a list of records in a table:
Product Cost Active
hat 1.00 false
coat 2.00 true
I have a DataGridView that shows purchases from a purchase table: Date, ProductID, Buyer
Is there a way to have a DataGridViewComboBoxColumn show only active items so that a user can only select active items in the puchases datagridview, but when they click a purchase from long ago when an item was active they have the ability to pick that old(unactive) item or a new one for an update.
Basically if I just have the ComboBoxColumn bound to a dataset with just active items, the datagrid will fail to load cause old purchases are not in its item list, but I also don't want all the items to be in the list.
So... you want a union of active items and inactive previously-bought items?select *
from Products
where Active = 'true' --Should you be using a bit/tinyint/smallint here?
UNION ALL
select distinct p.*
from
Purchases pu
join
Products p
on p.ProductID = pu.ProductID
where p.Active = 'false'
and pu.Buyer = @.Buyer
Maybe?
Rob|||Hi,
well this is more a front-end related question. You can capture the SelectedIndexchangedEvent of the Combobox and select upon the value or the column where the row is marked as new / old if it can be choosen or not. Depending on your control you could also use another color for each combobox value (and therefore hrey out the non selectable). If you want to filter the combobox values in the first place without showing them to the user, you might want to hook into the ItemDatabound event. That highly depends on your used language / controls (which you did not mentioned)
HTH; Jens K. Suessmeyer.
http://www.sqlserver2005.de|||I got it hammered out. I set the combobox data source on a filtered binding source when the OnBeginEdit event fired. The filtered string simply included and "or combobox.Value = sourceTable.ID". Then on the OnEndEdit event, I set the combobox datasource back to an unfiltered view of the items.
Relate two databases
that both use SQL Server 2000 to store data (database A and database
B). In the application logic we define relations between objects in
these products.
Is it possible to ensure that when restoring a database from a backup,
the other database is automatically restored at the same time to keep
data consistent between the two databases?
What I want to avoid is having a DBA restoring one database and
forgetting the other, thereby creating inconsistencies.
Kind regards,
Martin
Hi,
You can write a script to restore both the databases in order. So instead of
doing a manual restore you could just run the
restore script which loads both the database.
Some thing like:-
Alter database <db1> set single_user with rollback immediate
go
Restore database <db1> from disk='c:\backup\file_name.bak'
go
Alter database <db1> set Multi_user
go
Alter database <db2> set single_user with rollback immediate
go
Restore database <db2> from disk='c:\backup\file_name.bak'
go
Alter database <db2> set Multi_user
Thanks
Hari
MCDBA
"Martin Perfelian" <zonk99@.hotmail.com> wrote in message
news:b9c2729.0408110037.738ea8c2@.posting.google.co m...
> I am developing an application which consists of two separate products
> that both use SQL Server 2000 to store data (database A and database
> B). In the application logic we define relations between objects in
> these products.
> Is it possible to ensure that when restoring a database from a backup,
> the other database is automatically restored at the same time to keep
> data consistent between the two databases?
> What I want to avoid is having a DBA restoring one database and
> forgetting the other, thereby creating inconsistencies.
> Kind regards,
> Martin
|||Even tho Hari describes the correct method, you may still have problems...
Databases are backed up independently of one another. You must use the logs
and probably, roll both forward to the same point in time, otherwise you may
still get mis-matches
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Martin Perfelian" <zonk99@.hotmail.com> wrote in message
news:b9c2729.0408110037.738ea8c2@.posting.google.co m...
> I am developing an application which consists of two separate products
> that both use SQL Server 2000 to store data (database A and database
> B). In the application logic we define relations between objects in
> these products.
> Is it possible to ensure that when restoring a database from a backup,
> the other database is automatically restored at the same time to keep
> data consistent between the two databases?
> What I want to avoid is having a DBA restoring one database and
> forgetting the other, thereby creating inconsistencies.
> Kind regards,
> Martin
Relate two databases
that both use SQL Server 2000 to store data (database A and database
B). In the application logic we define relations between objects in
these products.
Is it possible to ensure that when restoring a database from a backup,
the other database is automatically restored at the same time to keep
data consistent between the two databases?
What I want to avoid is having a DBA restoring one database and
forgetting the other, thereby creating inconsistencies.
Kind regards,
MartinHi,
You can write a script to restore both the databases in order. So instead of
doing a manual restore you could just run the
restore script which loads both the database.
Some thing like:-
Alter database <db1> set single_user with rollback immediate
go
Restore database <db1> from disk='c:\backup\file_name.bak'
go
Alter database <db1> set Multi_user
go
Alter database <db2> set single_user with rollback immediate
go
Restore database <db2> from disk='c:\backup\file_name.bak'
go
Alter database <db2> set Multi_user
Thanks
Hari
MCDBA
"Martin Perfelian" <zonk99@.hotmail.com> wrote in message
news:b9c2729.0408110037.738ea8c2@.posting.google.com...
> I am developing an application which consists of two separate products
> that both use SQL Server 2000 to store data (database A and database
> B). In the application logic we define relations between objects in
> these products.
> Is it possible to ensure that when restoring a database from a backup,
> the other database is automatically restored at the same time to keep
> data consistent between the two databases?
> What I want to avoid is having a DBA restoring one database and
> forgetting the other, thereby creating inconsistencies.
> Kind regards,
> Martin|||Even tho Hari describes the correct method, you may still have problems...
Databases are backed up independently of one another. You must use the logs
and probably, roll both forward to the same point in time, otherwise you may
still get mis-matches
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Martin Perfelian" <zonk99@.hotmail.com> wrote in message
news:b9c2729.0408110037.738ea8c2@.posting.google.com...
> I am developing an application which consists of two separate products
> that both use SQL Server 2000 to store data (database A and database
> B). In the application logic we define relations between objects in
> these products.
> Is it possible to ensure that when restoring a database from a backup,
> the other database is automatically restored at the same time to keep
> data consistent between the two databases?
> What I want to avoid is having a DBA restoring one database and
> forgetting the other, thereby creating inconsistencies.
> Kind regards,
> Martinsql
Relate two databases
that both use SQL Server 2000 to store data (database A and database
B). In the application logic we define relations between objects in
these products.
Is it possible to ensure that when restoring a database from a backup,
the other database is automatically restored at the same time to keep
data consistent between the two databases?
What I want to avoid is having a DBA restoring one database and
forgetting the other, thereby creating inconsistencies.
Kind regards,
MartinHi,
You can write a script to restore both the databases in order. So instead of
doing a manual restore you could just run the
restore script which loads both the database.
Some thing like:-
Alter database <db1> set single_user with rollback immediate
go
Restore database <db1> from disk='c:\backup\file_name.bak'
go
Alter database <db1> set Multi_user
go
Alter database <db2> set single_user with rollback immediate
go
Restore database <db2> from disk='c:\backup\file_name.bak'
go
Alter database <db2> set Multi_user
Thanks
Hari
MCDBA
"Martin Perfelian" <zonk99@.hotmail.com> wrote in message
news:b9c2729.0408110037.738ea8c2@.posting.google.com...
> I am developing an application which consists of two separate products
> that both use SQL Server 2000 to store data (database A and database
> B). In the application logic we define relations between objects in
> these products.
> Is it possible to ensure that when restoring a database from a backup,
> the other database is automatically restored at the same time to keep
> data consistent between the two databases?
> What I want to avoid is having a DBA restoring one database and
> forgetting the other, thereby creating inconsistencies.
> Kind regards,
> Martin|||Even tho Hari describes the correct method, you may still have problems...
Databases are backed up independently of one another. You must use the logs
and probably, roll both forward to the same point in time, otherwise you may
still get mis-matches
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Martin Perfelian" <zonk99@.hotmail.com> wrote in message
news:b9c2729.0408110037.738ea8c2@.posting.google.com...
> I am developing an application which consists of two separate products
> that both use SQL Server 2000 to store data (database A and database
> B). In the application logic we define relations between objects in
> these products.
> Is it possible to ensure that when restoring a database from a backup,
> the other database is automatically restored at the same time to keep
> data consistent between the two databases?
> What I want to avoid is having a DBA restoring one database and
> forgetting the other, thereby creating inconsistencies.
> Kind regards,
> Martin
Relate a Contact to Customer
I have a contact table and a customer table. The two tables will contain columns like
First name
Last Name,
Date of Birth
Post Code,
House Number
Street Name
etc.
I would like to find the different combinations in which I can relate the customer and contact data.
Like its is possible that the first name and last name are same but date of birth is different. This indicates that the contact and customer is the same. Now I do not know these combinations and I would like to have this set generated for me.
From Integration Service (Sql Server 2005) I get the data and I would like to know the patterns in which data will differ. Is there any way of achieving this?
I am very new to Data Mining and would like to have some direction as to how to progress with this.
The fuzzy match functionality in Integration Services is a better solution for this problem.
Data Mining requires a training set that already has the patterns you wish to discover - once you train a mining model with that data set, you can then apply those patterns to new data and predict missing information (potentially, depending on the type of algorithm you use to build the model).