primary-key

How can I have a primary key in a VIEW (a key that doesn't depend on source tables)

◇◆丶佛笑我妖孽 提交于 2019-12-10 09:49:12
问题 I'm creating a VIEW out of 3 TABLES. Each TABLE has it's primary key. However, in the VIEW in order to have a primary key, I'll have to use a composite primary key (combination of primary keys of 3 TABLES). I would however like to add a column in the VIEW as a primary key that is created just for the purpose of the VIEW. As part of the VIEW definition, it should be UNIQUE(autoincrement since it would be mostly an INT). How can I achieve this? I am using MySQL 5.1 回答1: you could use various

Performance: UUID vs auto-increment in cakephp-mysql

冷暖自知 提交于 2019-12-10 09:33:31
问题 I was searching if UUID generated by cakePHP (32 char long) is faster in performance compared to auto-increment. Comparison in both inserts and Select operation. Which one should I use UUID generated by cakePHP or by using simple auto-increment of MySQL Here's is a case-study I found but its not specific to cakePHP http://krow.livejournal.com/497839.html 回答1: I doubt you're going to notice much of a performance issue in choice of primary key. Your bottlenecks will be somewhere else, almost

Violation of PRIMARY KEY constraint 'PK_Address'. etc…what am I doing wrong?

南笙酒味 提交于 2019-12-10 07:51:37
问题 Evening all. I am fairly new to SQL but have been doing quite a bit of fooling around. I am following a guide I found online to learn SQL in 21 days and I am having a bit of trouble figuring out what the error I am receiving is causing. I am trying to INSERT data into an existing table. The Primary Key for this table is AddressID . The data I am trying to enter is in the code below: INSERT INTO [dbo].[Address] (AddressID,Street,City,State,ZipCode) VALUES (1,'2400 Broadway','New York','NY'

guid as primary key?

故事扮演 提交于 2019-12-10 04:04:53
问题 I have a mysql database which has 3 tables that have to be joined together. I receive smaller databases that must feed this mysql database, appending the new data as I get it. The problem I have is the smaller dbs that I get are generated by an outside application and are not really meant to be used all together. Therefore, when I utilize the schema of the smaller database, I have no way to know how they all the records from the 3 tables belong together. I was thinking about inserting a guid

Best approach for multi-tenant primary keys

余生颓废 提交于 2019-12-10 03:19:28
问题 I have a database used by several clients. I don't really want surrogate incremental key values to bleed between clients. I want the numbering to start from 1 and be client specific. I'll use a two-part composite key of the tenant_id as well as an incremental id. What is the best way to create an incremental key per tenant? I am using SQL Server Azure. I'm concerned about locking tables, duplicate keys, etc. I'd typically set the primary key to IDENTITY and move on. Thanks 回答1: Are you

set two field primary key

跟風遠走 提交于 2019-12-10 02:23:11
问题 table1 id1 ==> number id2 ==> number id want id1 contain uniqe number and id2 contain unique number. how can set id1 and id2 primary key ? 回答1: In the Table Designer, Select both rows, and then click the Primary Key button in the Toolbar. OR, open the Query Designer, change the view to SQL View, and type the following code: ALTER TABLE your_table_name ADD CONSTRAINT your_pk_name PRIMARY KEY(id1, id2); Then, hit the run button. This will create a Primary key which includes both of those fields

Primary and foreign keys in xml schema

折月煮酒 提交于 2019-12-09 17:53:59
问题 I am trying to insert primary and foreign keys in XSD schema file below :- Primary key is StudentID and Foreign Keys are courseID, AddressID, GradeID. <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Student"> <xs:complexType> <xs:sequence> <xs:element name="Title" type="xs:string"/> <xs:element name="FirstName" type="xs:string"/> <xs:element name="LastName" type="xs:string"/> <xs:element name="Dateborn" type="xs:date"/> <xs:element name="Gender"

Using both a GUID and an auto-incrementing integer

走远了吗. 提交于 2019-12-09 15:58:56
问题 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

SQLite query to find primary keys

只谈情不闲聊 提交于 2019-12-09 14:45:30
问题 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

Use composite keys? Or always use surrogate keys?

偶尔善良 提交于 2019-12-09 14:31:06
问题 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 回答1: 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