primary-key

What happens when DB engine runs out of numbers to use for primary keys?

谁说胖子不能爱 提交于 2019-12-01 19:19:31
Since DBs do not reuse numbers of deleted records it is possible to run out of numbers, especially if you pick not really a big integer type for this column. What would happen and how to prevent it if it's bad? // SQL Server, MySQL // I think exactly what happens will be dependent on which database engine you're using (there may even be differences between INNODB and MyISAM in MySQL). Whatever happens, it's not going to be pretty. You'd simply have to change the column type to a larger integer. You end up with a 3+ Hour Downtime, like Slashdot did on their Comments-Function. For MySQL, it is

Identity-like column but based on Group By criteria

心不动则不痛 提交于 2019-12-01 19:05:23
In my SQL Server 2012 database, I'm creating a "Tasks" table that will have a compound primary key composed of three fields: Issue_ID [int] NOT NULL, Issue_Sub_ID [int] NOT NULL, Task_ID [int] NOT NULL Issue_ID and Issue_Sub_ID are foreign keys to other tables. In the table I'm creating, there can be many tasks associated with each Issue_ID / Issue_Sub_ID combination. What I would like to do is establish a default value for the Task_ID column, similar to if I used IDENTITY(1,1) , but that will auto-increment based on the Issue_ID / Issue_Sub_ID group. For example, the Task_ID results would

MySql primary key constraint with name

半世苍凉 提交于 2019-12-01 18:58:34
Data definition statement: CREATE TABLE Persons ( P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255), CONSTRAINT pk_PersonID PRIMARY KEY (P_Id) ) What is the value and purpose of CONSTRAINT pk_PersonID PRIMARY KEY (P_Id) ? as opposed to this PRIMARY KEY (P_Id) ? MySql docs do not really say much about this except for this . Marki555 It's the same as MySQL ignores the CONSTRAINT pk_PersonID part. You can check by creating the table and then dumping it or issuing SHOW CREATE TABLE Persons . I guess it supports this syntax only for

Setting primary key start value in Django model

梦想与她 提交于 2019-12-01 18:49:29
I am preparing a model as follows: class SomeModel(models.Model): id = models.BigIntegerField(primary_key=True, null=False, unique=True) But my primary key must be a valid 9+ digit integer value. If I set the start index as 100000000 . then any value generated as id will be 9 digit or greater in length. But django do not support this. How can I implement this with minimum direct interference to django? I am using Django 1.3 and Postgresql 9.1 I'm not a django user but I think the postgresql command you are looking for is: ALTER SEQUENCE big_integer_seq RESTART 100000000; Best to read the

What happens when DB engine runs out of numbers to use for primary keys?

99封情书 提交于 2019-12-01 18:29:08
问题 Since DBs do not reuse numbers of deleted records it is possible to run out of numbers, especially if you pick not really a big integer type for this column. What would happen and how to prevent it if it's bad? // SQL Server, MySQL // 回答1: I think exactly what happens will be dependent on which database engine you're using (there may even be differences between INNODB and MyISAM in MySQL). Whatever happens, it's not going to be pretty. You'd simply have to change the column type to a larger

does it worth switching a PRIMARY KEY from the type NVARCHAR to the type INT?

坚强是说给别人听的谎言 提交于 2019-12-01 18:22:55
On our SQL SERVER 2008 R2 database we have an COUNTRIES referential table that contains countries. The PRIMARY KEY is a nvarchar column: create table COUNTRIES( COUNTRY_ID nvarchar(50) PRIMARY KEY, ... other columns ) The primary key contains values like 'FR', 'GER', 'US', 'UK', etc. This table contains max. 20 rows. We also have a SALES table containing sales data: create table SALES( ID int PRIMARY KEY COUNTRY_ID nvarchar(50), PRODUCT_ID int, DATE datetime, UNITS decimal(18,2) ... other columns ) This sales table contains a column named COUNTRY_ID , also of type nvarchar (not a primary key).

Update primary key Django MySQL

家住魔仙堡 提交于 2019-12-01 17:00:27
sorry for my poor english, my problem is: I try to update the PK in Django with the method .save() but when i save the object Django duplicate the object withe the same data but differetn PK, example: from gestion_empleados.Models import Empleados >>> e = Empleados.objects.get(pk="56789034U") >>> e.pk u'56789034U' >>> e.pk = "11111111L" >>> e.save() >>> e.pk '11111111L' >>> e2 = Empleados.objects.get(pk="56789034U") >>> e2 <Empleados: Juan 56789034U> >>> e <Empleados: Juan 11111111L> The objects are the same with different PK, and i want change the PK without duplicated the object. Any

Can adding a primary key identity column solve deadlock issues?

心已入冬 提交于 2019-12-01 15:51:46
I have a table in SQL server that is CRUD-ed concurrently by a stored procedure running simultaneously in different sessions: |----------------|---------| | <some columns> | JobGUID | |----------------|---------| The procedure works as follows: Generate a GUID. Insert some records into the shared table described above, marking them with the GUID from step 1. Perform a few updates on all records from step 2. Select the records from step 3 as SP output. Every select / insert / update / delete statement in the stored procedure has a WHERE JobGUID = @jobGUID clause, so the procedure works only

Can adding a primary key identity column solve deadlock issues?

吃可爱长大的小学妹 提交于 2019-12-01 14:57:26
问题 I have a table in SQL server that is CRUD-ed concurrently by a stored procedure running simultaneously in different sessions: |----------------|---------| | <some columns> | JobGUID | |----------------|---------| The procedure works as follows: Generate a GUID. Insert some records into the shared table described above, marking them with the GUID from step 1. Perform a few updates on all records from step 2. Select the records from step 3 as SP output. Every select / insert / update / delete

rails non-integer primary key

天大地大妈咪最大 提交于 2019-12-01 14:47:46
I have a table called Contracts. Its current default primary key is the :id field that Rails automatically generates, which is an integer. I want to have a field called contractId that is a string type and use it as a primary key instead. What I want to know is: Is this a best practice? Are there any potential issues with doing this? How I would go about it Ruby on Rails (RoR) likes to emphasise the concept of convention over configuration . Therefore, it seeks to minimialise the amount of configuration. So if you want contractId that is a string type then you can add one extra field in your