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

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

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

問題描述

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

使用此架構,您可以為一對位置創(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.

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

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

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 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() 是否應該返回“1?什么時候不能投射為日期?)
主站蜘蛛池模板: 免费特黄视频 | 日韩中文字幕在线视频观看 | 精品一区二区三区在线视频 | 国产综合一区二区 | 中文字幕av高清 | 亚洲精品久久久一区二区三区 | 国产精品一二区 | 中文字幕高清一区 | 午夜影院在线免费观看视频 | 成人精品视频在线观看 | a在线免费观看视频 | 日韩三级 | 免费v片 | 亚洲精品一区二区三区在线 | 中文字幕亚洲一区 | 精品一二三区 | 亚洲狠狠丁香婷婷综合久久久 | 日韩av在线不卡 | 成人精品一区二区三区中文字幕 | 久久久久久久久久久高潮一区二区 | 欧美日韩精品免费 | 亚洲精品美女 | 国产精品一区在线观看 | 国产精品a一区二区三区网址 | 国产免费一级一级 | 色姑娘综合网 | 国产精品视频一区二区三区, | 日本特黄特色aaa大片免费 | 日日干夜夜操天天操 | 国产成人精品综合 | 亚洲欧美日韩网站 | 成人h免费观看视频 | 午夜激情小视频 | 国产欧美精品一区二区 | 91.com视频| 一级黄色影片在线观看 | 性一交一乱一透一a级 | 久久中文一区二区 | 91久久综合 | 久久久久久国产精品免费免费 | av一级久久 |