In that case, I don't think a replication situation will work.
What I would do is get your tables right (see below).
I would assign a guid to each unique computer name.
Then your list of UserTable (UserInfo below) will always contain a FK
reference to the ComputerName.
Thus, whenever you insert a list of users, you'll always have to use the
computerName (which you have) to lookup the ComputerUUID (PK for Computer),
before inserting users.
The tables def I give below will allow you to set up your ref integrity
BEFORE you do imports. That's one bonus of using a guid. Be aware there
are some performance factors of guids as PK's.
But for your need I would go that way. (google guid vs identity for
articles about this issue).
I'm a little confused about how why your clients need to get the data back
from the serverDB. Just as a sync up / refresh? Since they hold the data
for their machine to begin with.
Anyway, hopefully this will give you an idea. I figured the clients were
using something besides Sql Server (my guess was Access, but you said some
propietary database.
Good luck:
/*
Each computer in the system has a database with a table of users and
their telephone numbers.
Each computer has a unique 4 digit identifying code.
*/
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[TelephoneInfo]') and OBJECTPROPERTY(id, N'IsUserTable') =
1)
BEGIN
DROP TABLE [dbo].[TelephoneInfo]
END
GO
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[UserInfo]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
DROP TABLE [dbo].[UserInfo]
END
GO
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[ComputerName]') and OBJECTPROPERTY(id, N'IsUserTable') =
1)
BEGIN
DROP TABLE [dbo].[ComputerName]
END
GO
CREATE TABLE [dbo].[ComputerName] (
[ComputerUUID] [uniqueidentifier] primary key not null default
NEWSEQUENTIALID() ,
ComputerName varchar(64) not null -- this would hold the friendly computer
name
--like jsmithbox, mjonesbox, stuff like that
CONSTRAINT CN_CName_UNIQUE UNIQUE (ComputerName)
)
GO
CREATE TABLE [dbo].[UserInfo] (
[UserInfoUUID] [uniqueidentifier] primary key not null default
NEWSEQUENTIALID() ,
--FK to the specific computer.
[ComputerUUID] [uniqueidentifier] not null FOREIGN KEY (ComputerUUID)
REFERENCES dbo.ComputerName(ComputerUUID),
UserName varchar(64) not null ,
CONSTRAINT UserInfo_UserNamePerComputer_UNIQUE UNIQUE (ComputerUUID ,
UserName) --THis says that each username is unique ON EACH COMPUTER
)
GO
CREATE TABLE [dbo].[TelephoneInfo] (
[TelephoneInfoUUID] [uniqueidentifier] primary key not null default
NEWSEQUENTIALID() ,
--FK to the specific user.
[UserInfoUUID] [uniqueidentifier] not null FOREIGN KEY (UserInfoUUID)
REFERENCES dbo.UserInfo(UserInfoUUID),
TelephoneNumber varchar(16) not null , -- (000) 000-0000
CONSTRAINT User_TelephoneNum_UNIQUE UNIQUE (UserInfoUUID ,
TelephoneNumber) --THis prevents duplicate phone numbers for the same User
)
GO
INSERT INTO [dbo].[ComputerName] ( [ComputerUUID] , [ComputerName] )
values ( 'C0000000-0000-0000-0000-000000000001' , 'cbarkleyWin98Box')
INSERT INTO [dbo].[ComputerName] ( [ComputerUUID] , [ComputerName] )
values ( 'C0000000-0000-0000-0000-000000000002' , 'jsmithXPBox')
INSERT INTO [dbo].[ComputerName] ( [ComputerUUID] , [ComputerName] )
values ( 'C0000000-0000-0000-0000-000000000003' , 'mjonesWin2000Box')
select * from [dbo].[ComputerName]
INSERT INTO dbo.UserInfo ( UserInfoUUID , ComputerUUID , UserName )
values ( 'E0000000-0000-0000-0000-000000000111' ,
'C0000000-0000-0000-0000-000000000001' , 'andy apple' )
INSERT INTO dbo.UserInfo ( UserInfoUUID , ComputerUUID , UserName )
values ( 'E0000000-0000-0000-0000-000000000112' ,
'C0000000-0000-0000-0000-000000000001' , 'ben banana' )
INSERT INTO dbo.UserInfo ( UserInfoUUID , ComputerUUID , UserName )
values ( 'E0000000-0000-0000-0000-000000000113' ,
'C0000000-0000-0000-0000-000000000001' , 'cindy cucumber' )
INSERT INTO dbo.UserInfo ( UserInfoUUID , ComputerUUID , UserName )
values ( 'E0000000-0000-0000-0000-000000000222' ,
'C0000000-0000-0000-0000-000000000002' , 'henry hippo' )
INSERT INTO dbo.UserInfo ( UserInfoUUID , ComputerUUID , UserName )
values ( 'E0000000-0000-0000-0000-000000000223' ,
'C0000000-0000-0000-0000-000000000002' , 'larry lama' )
INSERT INTO dbo.UserInfo ( UserInfoUUID , ComputerUUID , UserName )
values ( 'E0000000-0000-0000-0000-000000000224' ,
'C0000000-0000-0000-0000-000000000002' , 'mandy monkey' )
INSERT INTO dbo.UserInfo ( UserInfoUUID , ComputerUUID , UserName )
values ( 'E0000000-0000-0000-0000-000000000333' ,
'C0000000-0000-0000-0000-000000000003' , 'frank ford' )
INSERT INTO dbo.UserInfo ( UserInfoUUID , ComputerUUID , UserName )
values ( 'E0000000-0000-0000-0000-000000000334' ,
'C0000000-0000-0000-0000-000000000003' , 'gary gm' )
INSERT INTO dbo.UserInfo ( UserInfoUUID , ComputerUUID , UserName )
values ( 'E0000000-0000-0000-0000-000000000335' ,
'C0000000-0000-0000-0000-000000000003' , 'henry honda' )
select * from [dbo].UserInfo
--You don't have to specify the PK, you can let sql server do it for you.
--I just did this to help with fake populate and data ref integrity
insert into [dbo].[TelephoneInfo] ( [UserInfoUUID], TelephoneNumber )
values ( 'E0000000-0000-0000-0000-000000000111' , '919-000-0001' )
insert into [dbo].[TelephoneInfo] ( [UserInfoUUID], TelephoneNumber )
values ( 'E0000000-0000-0000-0000-000000000112' , '919-000-0002' )
insert into [dbo].[TelephoneInfo] ( [UserInfoUUID], TelephoneNumber )
values ( 'E0000000-0000-0000-0000-000000000113' , '919-000-0003' )
insert into [dbo].[TelephoneInfo] ( [UserInfoUUID], TelephoneNumber )
values ( 'E0000000-0000-0000-0000-000000000222' , '540-001-0001' )
insert into [dbo].[TelephoneInfo] ( [UserInfoUUID], TelephoneNumber )
values ( 'E0000000-0000-0000-0000-000000000223' , '540-001-0002' )
insert into [dbo].[TelephoneInfo] ( [UserInfoUUID], TelephoneNumber )
values ( 'E0000000-0000-0000-0000-000000000224' , '540-001-0003' )
insert into [dbo].[TelephoneInfo] ( [UserInfoUUID], TelephoneNumber )
values ( 'E0000000-0000-0000-0000-000000000333' , '703-002-0001' )
insert into [dbo].[TelephoneInfo] ( [UserInfoUUID], TelephoneNumber )
values ( 'E0000000-0000-0000-0000-000000000334' , '703-002-0002' )
insert into [dbo].[TelephoneInfo] ( [UserInfoUUID], TelephoneNumber )
values ( 'E0000000-0000-0000-0000-000000000335' , '615-003-0006' )
insert into [dbo].[TelephoneInfo] ( [UserInfoUUID], TelephoneNumber )
values ( 'E0000000-0000-0000-0000-000000000335' , '615-003-0007' )
insert into [dbo].[TelephoneInfo] ( [UserInfoUUID], TelephoneNumber )
values ( 'E0000000-0000-0000-0000-000000000335' , '615-003-0008' )
select * from [dbo].[TelephoneInfo]
print ''
print ''
Select cn.ComputerName, u.UserName, t.TelephoneNumber from dbo.ComputerName
cn join dbo.UserInfo u on cn.[ComputerUUID] = u.[ComputerUUID]
join [dbo].[TelephoneInfo] t on u.[UserInfoUUID] = t.[UserInfoUUID]
Order by cn.ComputerName, u.UserName, t.TelephoneNumber
The key here, is that you can't add a new user with knowing the computer
they're associated with.
the other key (with the guid solution), means you can build your ref
integrity before pushing the data into the database.
in C#/DotNet you would do
Guid newComputerUUID = System.Guid.NewGuid();
You could also build up a strong dataset (dotnet) to hold all the
information before shipping it to sql server.
See this article:
http://www.sqlservercentral.com/articles/Stored+Procedures/thezerotonparameterproblem/2283/
Dont' focus on "report paramters", but rather how you can send xml into the
database and do something with it.