primary-key

How do I create a table with a two primary keys of two foreign keys?

邮差的信 提交于 2019-12-07 19:05:51
问题 create table Machine ( Machine_ID int primary key, Machine_Name varchar(30) Machine_Title varchar(30) ) create table Part ( Part_ID int primary key, Part_Name varchar(30), Part_Description varchar(30) ) //How do I make this table below? create table Machine-Part ( Machine_ID int foreign key references (Machine.Machine_ID), Part_ID int foreign key references (Part.Part_ID) Factory_Note varchar(30); ) Mysql complains there is a problem with syntax? Desired Result: have Table 'Machine-Part' use

Save detached object graph using Entity Framework code first causes Primary Key violation

孤人 提交于 2019-12-07 18:45:44
问题 I'm trying to save an object graph of POCOs I have mapped to EF6 using Code First fluent notations. Upon saving the object graph however, I stumble upon primary key violation exceptions. The object graph is quite simple: One Issue can contain multiple WorkItems with each one Author (as User ). The objects are populated externally (using a Web API) When I attempt to save an issue with two workitems which refer to the same author, I would expect the issue to be inserted, the workitems to be

Change primary key value in Oracle

让人想犯罪 __ 提交于 2019-12-07 13:59:23
问题 Is there a way to change the value of a primary key which is referenced by another table as foreign key? 回答1: An easier alternative is to insert a new row and delete the old one. (Update any referencing rows in other tables before you do the delete) 回答2: There isn't an in-built UPDATE CASCADE if that's what you're after. You'd need to do something like disable any FK constraints; run UPDATE statements; re-enable the constraints. Note that updating Primary Keys is (usually always) a bad idea.

Why use primary keys?

落花浮王杯 提交于 2019-12-07 10:45:10
问题 What are primary keys used aside from identifying a unique column in a table? Couldn't this be done by simply using an autoincrement constraint on a column? I understand that PK and FK are used to relate different tables, but can't this be done by just using join? Basically what is the database doing to improve performance when joining using primary keys? 回答1: Mostly for referential integrity with foreign keys,, When you have a PK it will also create an index behind the scenes and this way

Java: Merging two json objects together with primary key

半腔热情 提交于 2019-12-07 07:37:17
问题 Lets say I have two arrays of JSONObjects in memory and each object has a key that is similar in both arrays: Array 1 [ { "name": "Big Melons Co.", "location": "Inner City Dubai" "id": "1A" }, { "name": "Pear Flavored Juices Ltd", "location": "Seychelles" "id": "2A" }, { "name": "Squeeze My Lemons LLC", "location": "UK" "id": "3A" }, {other JSON Objects...} ] Array 2 [ { "acceptsCard": "true" "id": "1A" }, { "acceptsCard": "false" "id": "2A" }, { "acceptsCard": "false" "id": "3A" }, {other

prevent autoincrementing integer primary key?

蹲街弑〆低调 提交于 2019-12-07 06:43:16
问题 I have a sqlite table (sqlite version 3.7.3) where nulls inserted into the primary key column are being undesirably auto-incremented: sqlite> CREATE TABLE foo(bar INTEGER NOT NULL PRIMARY KEY); sqlite> INSERT INTO foo(bar) VALUES(NULL); sqlite> SELECT * FROM foo; 1 In the sqlite docs, it shows that adding the AUTOINCREMENT keyword to the column should create this behavior, but there doesn't appear to be a keyword to prevent the auto incrementing... I also found that I can build sqlite with

PHP MySQL Check If A Table Has A Primary Key

人盡茶涼 提交于 2019-12-07 06:13:38
问题 What would I query my MySQL server to check if a table has a primary key or not? Something like: if(mysql_send("SELECT TABLE table HAS PRIMARY KEY") == TRUE) { // do stuff here } 回答1: SHOW INDEXES FROM TABLE WHERE Key_name = 'PRIMARY' 回答2: SELECT EXISTS( SELECT 1 FROM information_schema.columns WHERE table_schema = 'db' and table_name='table name' and column_key = 'PRI' ) As HasPrimaryKey 来源: https://stackoverflow.com/questions/4982558/php-mysql-check-if-a-table-has-a-primary-key

MySQL Views in Navicat - How to define 'primary key'?

我们两清 提交于 2019-12-07 05:19:28
问题 Often when I define a View in Navicat I receive the following message: xxx does not have a primary key. Updates to this table will be done using the following pseudo statement: UPDATE xxx SET ModifiedFieldsAndValues WHERE AllFieldsAndOldValues LIMIT 1 Obviously I only use my Views for viewing data, not updating . But this did make me curious: Is there a way to define a "primary key" or "unique index" on a View? 回答1: its implied that the view uses the indices and primary keys of its base table

Error Code: 1062. Duplicate entry 'PRIMARY'

心已入冬 提交于 2019-12-07 04:24:57
问题 So, my professor gave me tables to insert it in a database but when I execute his code, MySQL is constantly giving the Error Code: 1062. Here is the conflict tables and the inserts: TABLES CREATE TABLE FABRICANTES( COD_FABRICANTE integer NOT NULL, NOMBRE VARCHAR(15), PAIS VARCHAR(15), primary key (cod_fabricante) ); CREATE TABLE ARTICULOS( ARTICULO VARCHAR(20)NOT NULL, COD_FABRICANTE integer NOT NULL, PESO integer NOT NULL , CATEGORIA VARCHAR(10) NOT NULL, PRECIO_VENTA integer, PRECIO_COSTO

How to manually set entity primary key in Entity Framework code first database?

僤鯓⒐⒋嵵緔 提交于 2019-12-07 03:46:17
问题 Well, I have the following model structure: I have one class - DatabaseEntity which is basically public class DatabaseEntity { public int Id { get; set; } } so each entity like product, category etc will inherit DatabaseEntity and have Id property. Also I have typical EntityFramework repository class with InsertOrUpdate method: private readonly DbContext _database; public void InsertOrUpdate<TObject>(TObject entity) where TObject : DatabaseEntity { if(entity.Id == default(int)) { // New