primary-key

Table update on PK and another field in MySQL is sporadically slow

和自甴很熟 提交于 2019-12-11 04:12:33
问题 This is interesting case where UPDATE in MySQL is sporadically slow. Background: 48GB Innodb buffer cache, 512MB ib logs. Innodb table with 40mln rows. Structure and indexes: CREATE TABLE `VisitorCompetition` ( `VisitorCompetitionId` bigint(20) NOT NULL AUTO_INCREMENT, `UserId` bigint(20) NOT NULL, `CompetitionInstanceId` bigint(20) NOT NULL, `Score` bigint(20) NOT NULL DEFAULT '0', `Visits` bigint(20) DEFAULT NULL, `Status` varchar(255) NOT NULL, `RankAtCompletion` int(11) DEFAULT NULL,

How to migrate from a composite primary key to a single attribute key in SQL?

泪湿孤枕 提交于 2019-12-11 03:40:40
问题 I would like to migrate a table that uses a composite primary key to a unique primary key. My table is as follow: CREATE TABLE REGM ( LNG_CD VARCHAR2(2 BYTE) NOT NULL ENABLE, REG_NRI NUMBER(10,0) NOT NULL ENABLE, ... CONSTRAINT PK_REGM PRIMARY KEY (LNG_CD, REG_NRI) ENABLE, ); The table REGM uses LNG_CD and REG_NRI as a composite primary key. I would like to uses a primary key name REGM_PK instead, but still uses LNG_CD and REG_NRI as foreign key. So far, this is my approach: 1 - Drop the

Specify how primary keys are generated during SSIS XML import

戏子无情 提交于 2019-12-11 03:02:05
问题 The problem is I import data into relational tables where the source of the data is a XML-file + XSD schema. The XML source has several outputs and the relationships between nodes is created by SSIS in columns as order_id (generated primary key value not in XML) and in lets say order details we get the foreign key order_id. The file gets imported and we have a correct referential integrity between lets say orders and order details but the key is only unique within each file so if same file is

Django Save Object based on PK and another field

送分小仙女□ 提交于 2019-12-11 02:46:37
问题 I am trying to use a partitioned table in postgresql together with a Django installation. From Googleing the subject, I found out, that Django does not support partitioning by itself, so I did the partitioning of the table myself. I partition my table based on a second field which is a foreign key on another table. The basic model setup is like so: class Event(models.Model): id = models.AutoField(primary_key=True) device = models.ForeignKey("Device") ... (More Fields) I have Partitioned the

MySQL performance using AUTO_INCREMENT on a PRIMARY KEY

回眸只為那壹抹淺笑 提交于 2019-12-10 23:58:08
问题 I ran a comparison INSERTing rows into an empty table using MySQL 5.6. Each table contained a column ( ascending ) that was incremented serially by AUTO_INCREMENT, and a pair of columns ( random_1 , random_2 ) that receive random, unique numbers. In the first test, ascending was PRIMARY KEY and ( random_1 , random_2 ) were KEY. In the second test, ( random_1 , random_2 ) were PRIMARY KEY and ascending was KEY. CREATE TABLE clh_test_pk_auto_increment ( ascending_pk BIGINT UNSIGNED NOT NULL

How to achieve unique auto-incremented id for rows across multiple tables?

荒凉一梦 提交于 2019-12-10 23:19:40
问题 I've got several tables in a database, let's say they're called table1, table 2, etc. All tables have a primary key column 'id' with auto-increment. In my current configuration it happens that when inserting into table1, the generated id is 1. Afterwards when inserting into table2, the generated id happens to be 1 as well. How to force absolutely unique ids across all tables in a database? I want when inserting into table1, generated id to be 1, and if afterwards inserting into table2,

Composite primary keys in sqlite

六月ゝ 毕业季﹏ 提交于 2019-12-10 19:09:32
问题 PRIMARY KEY(col1, col2) creates a index called "sqlite_autoindex_mytable_1". I saw it in "SQlite Expert". And in the "fields to index" box it shows both col1 and col2. In this post: https://dba.stackexchange.com/a/14260 it says that I have to create separate indexes for col2 if I want to use col2 in JOIN queries without col1. So I would need to add: CREATE INDEX "myidx" ON "mytable"("col2"); If I have this query: SELECT t2.* FROM mytable as t1 INNER JOIN mytable2 as t2 ON t1.col2 = t2.id do I

How to have a primary key with null values using empty string?

孤街浪徒 提交于 2019-12-10 18:50:02
问题 I have a table in which I need both the values to be primary because I am referencing this combination as foreign key in the other tables. Table definition and the data I need to put are as follows create table T1 ( sno number(10), desc varchar2(10), constraint T1_PK primary key(sno,desc) ) DATA to put sno | desc --------------------------- 100 | "hundred" 000 | null 120 | "one twenty" 123 | "" <EMPTY STRING> 000 | "" <EMPTY STRING> Problem here is desc can be sometimes be null. Primary key

What could be causing the primary key exception?

荒凉一梦 提交于 2019-12-10 18:36:16
问题 My ASP pages store session variables in SQL Server with the following stored procedure: CREATE PROCEDURE [dbo].[MyProcedure] @sessionId varchar(512), @variable varchar(350), @value image AS BEGIN BEGIN TRAN DECLARE @result int = 0; DECLARE @locked bit; IF (SELECT COUNT(*) FROM Sessions WHERE id = @sessionId) = 0 BEGIN SET @result = -1; END ELSE BEGIN DELETE Variables WHERE sessionId = @sessionId AND variable = @variable IF @value IS NOT NULL BEGIN INSERT Variables VALUES(@sessionId, @variable

EF entity without a public key

限于喜欢 提交于 2019-12-10 17:48:34
问题 I want to create an entity in EF without a public key. The backing table has got a non-unique clustered key, but the data in the table conceptually doesn't have a unique primary key it can use. It looks like EF really doesn't like this. Is there any way of getting EF to accept that the table has no primary key and make it work with it anyway, with no performance hit? I don't care if the result is read-only. 回答1: As I understand it, as the Entity Framework is based on the Domain Driven Design