久久久久久久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精品国产综合久久久密闭 | 91爱爱·com| 亚洲综合在线视频 | 91在线一区 | 午夜日韩| 亚洲毛片 | 成人久久久久久久久 | 日韩视频中文字幕 | 成人日韩av| 午夜精品一区 | 久草中文在线 | 色精品| 国产欧美视频一区 | 国产亚洲精品久久久久久豆腐 | 久久网日本 | 91精品国产色综合久久不卡蜜臀 | 免费成人在线网站 | 欧美久久久久 | 久久久蜜桃一区二区人 | 欧美aⅴ片 | 成人欧美一区二区三区在线播放 | 成人性视频免费网站 | www.887色视频免费 | 久久久久久久91 | 亚洲综合在线播放 | 亚洲美乳中文字幕 | 超碰成人免费 | 午夜一级黄色片 | 欧美区在线观看 | 中文字幕日韩欧美一区二区三区 | 日本午夜精品一区二区三区 | 婷婷丁香在线视频 | 国产农村妇女毛片精品久久麻豆 | 91高清免费 | 免费观看一级毛片 | 国产精品久久久久久久久久 | 91精品国产综合久久久久久漫画 | 亚洲精品久久视频 | 国产精品视屏 | 精品国产乱码久久久久久88av | 九九九久久国产免费 |