Click here to Skip to main content
15,917,631 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating client-server application architecture for database and local machine will access remote database file, so there is possibility of data duplication like one roll no allocated to two student

For Ex.
Machine 1 Access Table Student and insert new record number as 1
Machine 2 Access Table Student and insert new record number as 1

What I have tried:

I have given primary key to that field but it doesn't work
Posted
Updated 29-Aug-17 0:31am

Two options:
1) Use an IDENTITY field: IDENTITY (Property) (Transact-SQL) | Microsoft Docs[^] - the DB then takes control of the column and assigns values for you so that there is no duplication.
2) Use a UNIQUEIDENTIFER field: uniqueidentifier (Transact-SQL) | Microsoft Docs[^] and set it's value from your C# code via a Guid (or set the default property of the column to NEWID: NEWID (Transact-SQL) | Microsoft Docs[^] )
 
Share this answer
 
I have already faced this situation

Try to use unique or AUto increment
 
Share this answer
 
That's strange, a PRIMARY KEY automatically has a UNIQUE constraint defined on it. See: SQL PRIMARY KEY Constraint[^]
Are you sure the users are using the same database and table ?
But it is probably best to use IDENTITY, see: SQL AUTO INCREMENT a Field[^]
 
Share this answer
 
v2
With the help of
composite key
we can reduce the duplication when transfer data from one machine to another machine.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900