composite-primary-key

How to set (combine) two primary keys in a table

早过忘川 提交于 2019-12-01 15:03:34
问题 For a small sales related application, we designed database using logical data model. Come to the stage to convert in to physical model. While creating table in SQL Server Management Studio Express, according to our logical data model, we need to combine two attributes to form unique id. Is it possible to combine two primary keys and set it? But while observing Northwind Sample, we found that in the ORDER DETAILS table, we can see two primary keys Order Id & Product Id . And according to rule

How to use Django with legacy readonly database tables with composite primary keys?

*爱你&永不变心* 提交于 2019-12-01 11:46:31
I want to use Django for a client project that has a legacy database. If at all possible I would like to be able to use the Django admin interface. However, the database has tables with multicolumn primary keys, which I see Django does not like - the admin interface throws a MultipleObjectsReturned exception. What are the options here? I can add new tables, but I can't change existing tables since other projects are already adding data to the database. I've seen other questions mentioning surrogate keys, but it seems like that would require changing the tables. EDIT: The database in question

Composite Key functions in Hyperledger

穿精又带淫゛_ 提交于 2019-12-01 09:40:05
I need to implement composite keys in hyperledger so that I could have a unique key based on the attributes put into the ledger. The function CreateCompositeKey(objectType string, attributes []string)(string,error) takes in objectType and attributes string. I couldnt find any examples of this online, how are the relevant attributes to be made into the composite key passed and in what way is the output given? So the way Composite keys should be used is make a key first and then push it to the blockchain with PutState(key string, value []byte) error where the hey in PutState is the output of

How to use Django with legacy readonly database tables with composite primary keys?

自古美人都是妖i 提交于 2019-12-01 08:57:06
问题 I want to use Django for a client project that has a legacy database. If at all possible I would like to be able to use the Django admin interface. However, the database has tables with multicolumn primary keys, which I see Django does not like - the admin interface throws a MultipleObjectsReturned exception. What are the options here? I can add new tables, but I can't change existing tables since other projects are already adding data to the database. I've seen other questions mentioning

How should I define a composite primary key for an existing database table?

可紊 提交于 2019-12-01 06:50:41
问题 I'm working on a Core MVC project that reads data (no writing required) from a pre-existing database. Unfortunately this database is a total mess, but I cannot change anything in it (and even if I could, I wouldn't touch it with a 10-foot pole). Some of the relevant problems of the database are the following: The tables don't have any foreign key relations to each other, and contain data that would have best been entered into a sub-table; whoever created the database seems to have used tables

IN clause with a composite primary key in JPA criteria

旧街凉风 提交于 2019-11-30 20:12:36
I have a table named group_table in MySQL with only two columns user_group_id and group_id (both of them are of type VARCHAR ). Both of these columns together form a composite primary key. I need to execute a statement using a sub-select IN() to select rows based on a list of values passed to the query. @Override @SuppressWarnings("unchecked") public List<GroupTable> getList(List<GroupTable> list) { CriteriaBuilder criteriaBuilder=entityManager.getCriteriaBuilder(); CriteriaQuery<GroupTable> criteriaQuery=criteriaBuilder.createQuery(GroupTable.class); Root<GroupTable> root = criteriaQuery.from

SQLAlchemy joins with composite foreign keys (with flask-sqlalchemy)

こ雲淡風輕ζ 提交于 2019-11-30 20:10:26
I'm trying to understand how to do joins with composite foreign keys on SQLAlchemy and my attempts to do this are failing. I have the following model classes on my toy model (I'm using Flask-SQLAlchemy, but I'm not sure this has anything to do with the problem): # coding=utf-8 from flask import Flask from flask.ext.sqlalchemy import SQLAlchemy app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db' db = SQLAlchemy(app) class Asset(db.Model): __tablename__ = 'asset' user = db.Column('usuario', db.Integer, primary_key=True) profile = db.Column('perfil', db.Integer,

Mysql Select record where PRIMARY key = x

纵饮孤独 提交于 2019-11-30 18:17:25
问题 I have a primary key in my mysql table which is comprised of three columns. CREATE TABLE IF NOT EXISTS `bb_bulletin` ( `OfficeCode` int(5) NOT NULL, `IssuerId` int(11) NOT NULL, `BulletinDtm` datetime NOT NULL, `CategoryCode` varchar(4) NOT NULL, `Title` varchar(255) NOT NULL, `Content` text NOT NULL, PRIMARY KEY (`OfficeCode`,`IssuerId`,`BulletinDtm`), UNIQUE KEY `U_IssuerId` (`IssuerId`,`OfficeCode`,`BulletinDtm`), UNIQUE KEY `U_CategoryCode` (`CategoryCode`,`OfficeCode`,`IssuerId`,

JPA/Hibernate and composite keys

独自空忆成欢 提交于 2019-11-30 15:59:24
问题 I have come across some SO discussions and others posts (e.g. here, here and here) where using composite primary keys with JPA is described either as something to be avoided if possible, or as a necessity due to legacy databases or as having "hairy" corner cases. Since we are designing a new database from scratch and don't have any legacy issues to consider is it recommended or let's say, safer, to avoid composite primary keys with JPA (either Hibernate or EclipseLink ?). My own feeling is

What are the pros and cons of using multi column primary keys?

岁酱吖の 提交于 2019-11-30 12:07:12
问题 I would like to see an example of: When this is appropriate When this is not appropriate Is there a time when the choice of database would make a difference to the above examples? 回答1: This really seems to be a question about surrogate keys, which are always either an auto-incrementing number or GUID and hence a single column, vs. natural keys, which often require multiple pieces of information in order to be truly unique. If you are able to have a natural key that is only one column, then