加入收藏 | 设为首页 | 会员中心 | 我要投稿 济源站长网 (https://www.0391zz.cn/)- 数据工具、数据仓库、行业智能、CDN、运营!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

用于搜索具有无限数量的位字段的表的SQL设计方法

发布时间:2021-04-01 13:04:40 所属栏目:MsSql教程 来源:网络整理
导读:考虑搜索包含公寓租赁信息的表:使用该界面的客户端选择在数据库中表示为位字段的多个条件,例如: AllowPets HasParking HasDeck ModernKitchen 等等.. 我们面临的情况是,我们软件的每个新客户都有他们希望允许最终用户搜索的其他字段.位字段的数量可以达到数

定义表:

CREATE TABLE #Apartments
(
     ApartmentID    int          not null primary key identity(1,1),ApartmentName  varchar(500) not null,Status         char(1)      not null default ('A') 
    --....
)

CREATE TABLE #AttributeTypes
(
    AttributeType         smallint     not null primary key,AttributeDescription varchar(500) not null
)

CREATE TABLE #Attributes  --boolean attributes,if row exists apartment has this attribute 
(
     ApartmentID     int not null --FK to Apartments.ApartmentID,AttributeID     int not null primary key identity(1,AttributeType   smallint  not null --fk to AttributeTypes
)

(编辑:济源站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读