久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

SQL 中是否有一種方法可以強制執(zhí)行無向邊的唯一

Is there in SQL a way to enforce unicity of undirected edge?(SQL 中是否有一種方法可以強制執(zhí)行無向邊的唯一性?)
本文介紹了SQL 中是否有一種方法可以強制執(zhí)行無向邊的唯一性?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..
create table Location (
id integer primary key(1, 1),
latitude decimal(8,6),
longitude decimal(9,6),
address varchar(100),
name varchar(60) unique
);

create table Journey (
id integer primary key(1,1),
id_from integer foreign key references Location(id),
id_to integer foreign key references Location(id),
name varchar(100) unique,
unique(id_from, id_to)
);

使用此架構(gòu),您可以為一對位置創(chuàng)建 2 條不同的旅程,一條用于進路,另一條用于返回.我想要的是為每對位置強制執(zhí)行一次旅程.有哪些選項可以做到這一點?

With this schema, you could create 2 different journeys for a pair of locations, one for the way in and one for the way back. What I want is to enforce a single journey for each pair of locations. What are the options to do that ?

推薦答案

最簡單的方法是強制執(zhí)行方向"然后使用唯一約束:

The simplest method is to enforce the "direction" and then use a unique constraint:

create table Journey (
    id integer primary key,
    id_from integer foreign key references Location(id),
    id_to integer foreign key references Location(id),
    name varchar(100) unique,
    unique(id_from, id_to),
    check (id_from < id_to)
);

但是,您必須記住插入值以使用觸發(fā)器來確保它們是有序的.

However you have to remember to insert the values in order to use a trigger to ensure that they are in order.

否則,您可以對最小值和最大值使用計算列,然后對其使用唯一約束.

Otherwise, you can use computed columns for the smallest and biggest values and then use a unique constraint on that.

這篇關(guān)于SQL 中是否有一種方法可以強制執(zhí)行無向邊的唯一性?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應(yīng)該使用什么 SQL Server 數(shù)據(jù)類型來存儲字節(jié) [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數(shù)據(jù))
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
How to convert #39;2016-07-01 01:12:22 PM#39; to #39;2016-07-01 13:12:22#39; hour format?(如何將“2016-07-01 01:12:22 PM轉(zhuǎn)換為“2016-07-01 13:12:22小時格式?)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應(yīng)該返回“1?什么時候不能投射為日期?)
主站蜘蛛池模板: 天天射天天爽 | 日韩精品免费观看 | 日本免费视频 | 欧美另类z0zx974 | 黄色国产片| 天天综合影院 | 精品国产一区二区三区四区 | 亚洲在线免费观看 | 午夜激情影视 | 成人三级小说 | 国产精品久久久久久久久久久久久久 | 久久久www成人免费精品 | 爱爱免费小视频 | 精品国产乱码久久久久久蜜臀网站 | 久久只有精品 | 欧美黄色网 | 长河落日 | 国产高清免费 | 日韩高清一区 | 亚洲国产成人精品女人 | 欧洲一区二区三区 | 天天干天天看 | 黄色一级生活片 | 91av免费 | 成人av一区二区三区在线观看 | 久久夜色精品国产欧美乱极品 | 久草视频在线播放 | 国产精品成人在线观看 | 香蕉综合网 | 亚洲青涩 | 国产精品网站在线观看 | 免费的黄色网址 | 九九九免费视频 | 国产精品第二页 | 亚洲精品黄 | 久久免费国产视频 | 美女综合网 | aaa级片 | 麻豆成人91精品二区三区 | av大全在线观看 | 黄色一级片免费看 |