当数据库是远程文件时,如何减少数据重复? [英] How do I reduce duplication of data when database is remote file?

查看:70
本文介绍了当数据库是远程文件时,如何减少数据重复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为数据库创建客户端 - 服务器应用程序架构,本地机器将访问远程数据库文件,因此有可能像一卷不分配给两个学生那样重复数据



对于Ex。

机器1访问表学生并将新记录编号插入1

机器2访问表学生并插入新记录编号为1



我尝试了什么:



我给了那个领域的主键但是它不起作用

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

推荐答案

两个选项:

1)使用IDENTITY字段:IDENTITY(Property)(Transact-SQL)| Microsoft Docs [ ^ ] - 然后数据库控制列并为您分配值,以便没有重复。

2)使用UNIQUEIDENTIFER字段: uniqueidentifier(Transact-SQL)| Microsoft Docs [ ^ ]并通过Guid从C#代码中设置它的值(或将列的默认属性设置为NEWID: NEWID(Transact-SQL)| Microsoft Docs [ ^ ])
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[^] )


我已经遇到过这种情况



尝试使用unique或AUto增量
I have already faced this situation

Try to use unique or AUto increment


这很奇怪, PRIMARY KEY 会自动拥有在它上面定义了UNIQUE约束。请参阅: SQL PRIMARY KEY Constraint [ ^ ]

您确定用户使用的是同一个数据库和表吗?

但最好使用 IDENTITY ,请参阅: SQL AUTO INCREMENT a Field [ ^ ]
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[^]


这篇关于当数据库是远程文件时,如何减少数据重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆