composite-primary-key

How can I define a composite primary key in SQL?

匆匆过客 提交于 2019-11-26 04:37:56
问题 How can I define a composite primary key consisting of two fields in SQL? I am using PHP to create tables and everything. I want to make a table name voting with fields QuestionID , MemeberID , and vote . And the Composite primary key consists of the fields QuestionID and MemberID . How should I do this? 回答1: Just for clarification: a table can have at most one primary key. A primary key consists of one or more columns (from that table). If a primary key consists of two or more columns it is

How I can put composite keys in models in Laravel 5?

两盒软妹~` 提交于 2019-11-26 02:10:39
问题 I have in my DataBase a table with two primary keys (id and language_id) and I need put it in my models. The default primaryKey in Models (Model.php in Laravel 5) is id, and I want that the primaryKeys will be id and id_language. I tried put it with arrays or a String with \',\' but it doesn\'t work. It says me that the array could not be converted in String. Please Help. Thanks! 回答1: You can't. Eloquent doesn't support composite primary keys. Here's a Github issue regarding this. 回答2: I

How to properly create composite primary keys - MYSQL

≡放荡痞女 提交于 2019-11-26 01:37:14
问题 Here is a gross oversimplification of an intense setup I am working with. table_1 and table_2 both have auto-increment surrogate primary keys as the ID. info is a table that contains information about both table_1 and table_2 . table_1 (id, field) table_2 (id, field, field) info ( ???, field) I am trying to decided if I should make the primary key of info a composite of the IDs from table_1 and table_2 . If I were to do this, which of these makes most sense? ( in this example I am combining

Can I have multiple primary keys in a single table?

那年仲夏 提交于 2019-11-26 01:34:45
问题 Can I have multiple primary keys in a single table? 回答1: A Table can have a Composite Primary Key which is a primary key made from two or more columns. For example: CREATE TABLE userdata ( userid INT, userdataid INT, info char(200), primary key (userid, userdataid) ); Update: Here is a link with a more detailed description of composite primary keys. 回答2: You can only have one primary key, but you can have multiple columns in your primary key. You can also have Unique Indexes on your table,