有人知道如何从SQL Server数据库关系图创建一对一关系吗?
As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...
有人知道如何从SQL Server数据库关系图创建一对一关系吗?
您需要在外键之上放置一个唯一键约束,因此它被限制为一对一关系。
假设您使用的是Sql Server 2008及以后版本和SSMS。
第二次再次单击“确定”后,SSMS设计器将显示相关表之间的键对键关系。这是一对一的关系。读作,一个表中的一条记录与另一个表的另一条记录直接相关。
i.e A ResolutionsTable - 1 : 1 - Resolution Types Read as one resolution has one resolution type applied to it, i.e, case closed or case ongoing, case pending law change, case denied? Of course people have different DB design skills so what works for one may not work for another db developer. Never the less the example is clear enough to understand.
希望这能帮助像我这样不懂sql语法的新手,他们更喜欢通过sql数据库图功能构建整个数据库。
如果你的表是这样创建的,
CREATE TABLE tableName ( id INT NOT NULL IDENTITY(1,1) CONSTRAINT[PK:tableName] PRIMARY KEY(id) , fkId INT NOT NULL CONSTRAINT[FK:tableName:tableFk] FOREIGN KEY(fkId) REFERENCES tableFk(id) ) CREATE TABLE tableFk ( id INT NOT NULL IDENTITY(1,1) CONSTRAINT[PK:tableFk] PRIMARY KEY(id) )
您可以使用此代码更改tableName以将tableName.fkId设置为唯一
ALTER TABLE tableName ADD UNIQUE (fkId)
您可以轻松使用MSSQL Management Studio。
即
表用户
uid(pk) username email
表_文件
pid(pk) f_name l_name user_id (fk)
接着,
4选择“添加”(从“索引/键”窗口,它将添加一个新名称)
5在“常规部分”中选择“列”,然后选择“user_id”
6在“常规部分”中,将“是唯一的”设置为true
7在“身份部分”中为(姓名)部分命名。在这种情况下,我将提供UK_user_id_profile
8完成所有上述步骤后,关闭“索引/键”窗口
9将“uid”(来自用户表)拖放到“user_id”(源自配置文件表)中
就是这样。
这背后的理论,外键应该是独一无二的。
You need to put a unique key constraint on top of the foreign key, so its restricted to one-one relationship.
这就是阿扎姆在帖子中所说的。
[万一,我使用的是MSSQL 2012]
干杯
我相信这个问题是关于如何在SQLServerManagementStudioDiagram窗口中创建一对一关系的。我有一个过程,您可以在SQLServerManagementStudio数据库关系图中创建一对一关系。
你完了!
当你使用以下内容时,它非常直接:
ALTER TABLE [Salary]
ADD CONSTRAINT FK_Salary_Employee FOREIGN KEY([EmployeeID])
REFERENCES [Employee]([ID]);
这应该奏效!!!
As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....
I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...
I ve got some code which sets up a datacontext. Often enough, the datacontext should be set to some underlying data collection, such as an ObservableCollection - but occasionally I d like to set it ...
I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...
NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...