database-design

Best way to design a table with m:n relation

独自空忆成欢 提交于 2020-01-25 11:54:04
问题 What is the best way to design a table for a m:n relation between two entities?? 回答1: Three tables. One defining the first entity, one defining the second, and a third representing the relationship between them. Table 1 (first entity): T1Id, T1Name Table 2 (second entity): T2Id, T2Name Table 3 (relationship): T1Id, T2Id 来源: https://stackoverflow.com/questions/29400091/best-way-to-design-a-table-with-mn-relation

Add (external) relationship (tagging) to existing Hibernate entities

坚强是说给别人听的谎言 提交于 2020-01-25 10:21:09
问题 I need to add a new many-to-many relationship to an existing Hibernate entity. I do not want to touch the original Hibernate entity bean or its configuration. What I am adding is a "tagging" feature that can be viewed as an external contribution and not part of the entity's data itself. I want to have a simple join table with only two columns, the entity primary key, and the tag id. Can I use Hibernate to manage this table without introducting a new (artificial) entity type that contains a

create unique constraints per user

核能气质少年 提交于 2020-01-25 09:50:06
问题 I am building a small app and at this point I am creating the database schema. I use PostgreSQL with Sequel and I have the two migrations: Sequel.migration do change do Sequel::Model.db.run 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp"' create_table :user do String :id, :type => :uuid, :primary_key => true, :default => Sequel.function(:uuid_generate_v4) DateTime :created_at DateTime :updated_at index :id, :unique => true end end end Sequel.migration do change do Sequel::Model.db.run 'CREATE

How to handle different types of users when loggin in?

左心房为你撑大大i 提交于 2020-01-25 07:05:11
问题 In an application I've been building, I have a users table. The users represent a firm's staff. I also implemented a role/permission system. Permissions are assigned to roles (staff, manager, director, etc.), and roles are assigned to users. Permissions prohibit the use of certain actions in the app. Now, I'm introducing another user type: customer (will also be able to log into the app). The customer fields are different from the user fields, so I can't store the customer information in

Best data structure for finding tags of nested locations

☆樱花仙子☆ 提交于 2020-01-25 06:43:39
问题 Somebody pointed out that my data structure architecture sucks. The task I have a locations table which stores the name of a location. Then I have a tags table which stores information about those locations . The locations have a hierarchie which I want to use to get all tags . Example Locations: USA <- California <- San Francisco <- Mission St Tags: USA: English California: Sunny California: West coast San Francisco: Sea side Mission St: Cable car station If somebody requests information

Oracle View Creation with a Database generated ID from a Sequence Object

随声附和 提交于 2020-01-24 23:56:27
问题 Can i create an oracle "View" with a DB generated Primary Key? I want to create a view with its ID being a DB generated ID from a Sequence object. 回答1: You can't do exactly that, but you can do something like this: select rownum, field1, field2 from... the rownum is an aoutogenerated field that holds exactly that, but it's assigned BEFORE ordering records, so if you have an ORDER BY clause, then you'll have to do this: Select rownum, * from (select .... order by ....) 来源: https:/

Foreign key refering to multiple tables

允我心安 提交于 2020-01-24 17:03:46
问题 I have 4 tables A(ida, name) B(ida, B-specific stuff) C(ida, C-specific stuff) D(ida, D-specific stuff) and i want that another table E could refer to just B OR C (not D). What can i write in the CREATE TABLE E ? 回答1: Seems to me that you are trying to use some kind of supertype/subtype -- as opposed to simple vertical partitioning. If so, do introduce a type-discriminator. Because this is generic example (A, B, C, D ..) it is hard to guess what relates to what, so here are two options as my

User lookup on encrypted database fields

半城伤御伤魂 提交于 2020-01-24 14:00:08
问题 Essentially I've got a table holding user data, all of which is AES encrypted (in BLOB fields). This means that none of those fields can be indexed which will slow down any queries on that table - especially since the entire table will need decrypting before any matches can be made... ... WHERE AES_DECRYPT(`user`.`email`, '{$sSomeKeyHere}') = '{$sSubmittedEmail}' So, what I want is a field that just contains a hash value, unencrypted, that can be indexed to use as a quick lookup. The best

Database Columns In Select or create statements [duplicate]

為{幸葍}努か 提交于 2020-01-24 00:23:12
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: What is the maximum number of columns in a PostgreSQL select query I am going to start a new project which requires a large number of tables and columns , using postgres I just want to ask that is number of columns in creating postgres tables are limited , If yes then what would be the MAX value for number of columns in CREATE and SELECT statements? 回答1: There is an official list of limits on the PostgreSQL

Database Design Brainstorming: Sale Prices

偶尔善良 提交于 2020-01-23 02:00:27
问题 I need to create a database solution to provide product discounting. Current tables: Products Columns: ProductId, ProductTypeId, ReleaseDate ProductPrices Columns: ProductPriceId, ProductPriceTypeId (one product may have n prices), ProductId, Price We want to be able to discount by ProductId and/or ProductTypeId and/or ProductPriceTypeId and/or ReleaseDate. Example sales: Discount a single ProductId. Discount all products of a specified ProductTypeId and ProductPriceTypeId. Discount all