primary-key

MySql primary key constraint with name

China☆狼群 提交于 2019-12-04 03:32:42
问题 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. 回答1: It's the same as MySQL ignores the CONSTRAINT pk_PersonID part. You can check by creating the table and

Why did Rails 5 changed “index” to “foreign key”?

醉酒当歌 提交于 2019-12-04 03:25:28
If you had this in Rails 4: t.references :event, index: true Now you could use foreign_key instead of index in Rails 5. I don't quite understand WHY they decided to do this, since the functionality remains the same, what you're adding is an INDEX, not a FOREIGN KEY to that column. In Rails 5 - when we reference a model, index on the foreign_key is automatically created. Migration API has changed in Rails 5 - Rails 5 has changed migration API because of which even though null: false options is not passed to timestamps when migrations are run then not null is automatically added for timestamps.

Update primary key Django MySQL

青春壹個敷衍的年華 提交于 2019-12-04 03:22:38
问题 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

Using both a GUID and an auto-incrementing integer

霸气de小男生 提交于 2019-12-04 03:21:58
I've been investigating the use of GUIDs as primary keys in databases. So far, the pros seem to outweigh the cons. However, I see one point where GUIDs may not be what I want. In my application, users should be able to identify objects based on a user-friendly ID. So, for example, if they want to get a specific product without typing in the full name, they can use the product's ID. GUIDs aren't easy to remember for something like that. The solution I've been thinking about is to use both a GUID and an auto-incrementing integer. The GUID would be the row's primary key, while the auto

Use composite keys? Or always use surrogate keys?

非 Y 不嫁゛ 提交于 2019-12-04 01:36:01
Duplicate: Many to Many Relation Design - Intersection Table Design If I have these tables (* = primary key): user id* name group id* name Is this better? user_group user_id* group_id* Or is this better? user_group id* user_id group_id I am always voting for keys that are as narrow as possible, static (never change) and thus I usually favor a surrogate INT as a key over a compound key. If you want to reference a compound key from another table, you'll always have to specify several conditions - which can get quite unwieldy at times! Also check out some of those links: http://www.agiledata.org

Will SQL Server 2005 penalize me for using an nvarchar(50) as a primary key, instead of an integer?

a 夏天 提交于 2019-12-04 01:06:22
I'm considering altering some tables to use nvarchar(50) as primary key instead of an int primary key. Using an int ID for a key really is irrelevant data, it's the string I'm interested in. What sort of performance hit will occur, or where do you research this? Other than cut and try that is. Jared You have hit upon one of the major "holy wars" of database design. The debate you're referring to is the "surrogate vs. natural key" argument that's been raging for as long as there have been RDBMSs (as nearly as I can tell). The debate essentially boils down to whether a representative key

SQLite query to find primary keys

送分小仙女□ 提交于 2019-12-04 00:54:05
In SQLite I can run the following query to get a list of columns in a table: PRAGMA table_info(myTable) This gives me the columns but no information about what the primary keys may be. Additionally, I can run the following two queries for finding indexes and foreign keys: PRAGMA index_list(myTable) PRAGMA foreign_key_list(myTable) But I cannot seem to figure out how to view the primary keys. Does anyone know how I can go about doing this? Note: I also know that I can do: select * from sqlite_master where type = 'table' and name ='myTable'; And it will give the the create table statement which

Should I obscure primary key values?

会有一股神秘感。 提交于 2019-12-04 00:51:16
I'm building a web application where the front end is a highly-specialized search engine. Searching is handled at the main URL, and the user is passed off to a sub-directory when they click on a search result for a more detailed display. This hand-off is being done as a GET request with the primary key being passed in the query string. I seem to recall reading somewhere that exposing primary keys to the user was not a good idea, so I decided to implement reversible encryption. I'm starting to wonder if I'm just being paranoid. The reversible encryption (base64) is probably easily broken by

@@IDENTITY after INSERT statement always returns 0

与世无争的帅哥 提交于 2019-12-04 00:23:04
问题 I need a function which executes an INSERT statement on a database and returns the Auto_Increment primary key. I have the following C# code but, while the INSERT statement works fine (I can see the record in the database, the PK is generated correctly and rows == 1), the id value is always 0. Any ideas on what might be going wrong? public int ExecuteInsertStatement(string statement) { InitializeAndOpenConnection(); int id = -1; IDbCommand cmdInsert = connection.CreateCommand(); cmdInsert

Change Primary Key to Composite Key (Primary Key already exists)

淺唱寂寞╮ 提交于 2019-12-04 00:21:03
问题 I am trying to change the primary key of a table in my SQL database from the existing key to a composite key, which does not include the existing column. The following code is not working due to the following error messages: DROP PRIMARY KEY: Incorrect Syntax near PRIMARY. Expecting COLUMN, CONSTRAINT, ID, or QUOTED_ID ADD PRIMARY KEY: Incorrect Syntax near PRIMARY. Expecting ID T-SQL code: ALTER TABLE AgentIdentification DROP PRIMARY KEY Number, ADD PRIMARY KEY (AgentId, IdIndicator) EDIT I