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

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

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

問題描述

限時送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)
);

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

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 ?

推薦答案

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

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)
);

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

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.

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

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

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節 [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數據)
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轉換為“2016-07-01 13:12:22小時格式?)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應該返回“1?什么時候不能投射為日期?)
主站蜘蛛池模板: 我想看一级黄色毛片 | 亚洲国产精品久久 | 韩日精品视频 | 日韩视频一区二区三区 | 成人在线小视频 | 国产精品国产精品国产专区不片 | 日日干天天操 | 色综合成人网 | 麻豆精品国产91久久久久久 | 精品国产黄a∨片高清在线 www.一级片 国产欧美日韩综合精品一区二区 | 免费午夜视频在线观看 | 一级黄大片| 国产成人精品999在线观看 | 免费看国产片在线观看 | 国产三级网站 | 国产精品视频综合 | 最新免费黄色网址 | 在线视频国产一区 | 大象视频一区二区 | www.伊人.com | 久草影视在线 | 成人一区二区三区在线观看 | 日本小电影网站 | 99久久精品国产毛片 | 久久久精品综合 | 亚洲成人综合社区 | 欧美乱淫视频 | 国产一区在线看 | 一区中文字幕 | 久久久精品日本 | 日本aⅴ中文字幕 | 精品网 | 国产成人一区二区三区 | 在线免费观看黄a | 视频一区中文字幕 | 国产精品99久久久久久www | 精品九九| 日韩人体视频 | 日韩另类视频 | 亚洲 欧美 精品 | 日韩欧美专区 |