primary-key

Don't allow reversed composite primary key in MySQL

若如初见. 提交于 2019-12-02 02:39:22
I'm developing an application which needs to hold data about distances between two cities. I have created a distance table in the Mysql database which holds the name of the two cities and the distance between them. I have made the two town columns a composite primary key. I'd like the database to restrict the application from making duplicated reversed entries like shown on the screenshot to prevent having different distance values. What would be the best solution to solve this problem? You could create a stored procedure to insert into this table. DELIMITER $$ CREATE PROCEDURE insert_distance

Primary Keys in Oracle and SQL Server

你说的曾经没有我的故事 提交于 2019-12-02 02:22:00
问题 What's the best practice for handling primary keys using an ORM over Oracle or SQL Server? Oracle - Should I use a sequence and a trigger or let the ORM handle this? Or is there some other way ? SQL Server - Should I use the identifier data type or somehow else ? 回答1: If you are using any kind of ORM, I would suggest you to let it handle your primary keys generation. In SQL Server and Oracle. 回答2: With either database, I would use a client-generated Guid for the primary key (which would map

iPhone Core Data Fetch Primary Key

孤街醉人 提交于 2019-12-02 02:15:39
问题 I am developing an application that uses CoreData. So in .sqlite file, It manages Primary key itself. Primary key attribute name is Z_PK . My problem is that, I wants data from my table sorted ascending by primary key. I'm using that code NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"_PK" ascending:YES]; [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]]; [sort release]; But it's not working. when I'm using "title" insted of "_PK", It's working Fine

Primary Keys in Oracle and SQL Server

强颜欢笑 提交于 2019-12-02 02:07:52
What's the best practice for handling primary keys using an ORM over Oracle or SQL Server? Oracle - Should I use a sequence and a trigger or let the ORM handle this? Or is there some other way ? SQL Server - Should I use the identifier data type or somehow else ? Pablo Santa Cruz If you are using any kind of ORM, I would suggest you to let it handle your primary keys generation. In SQL Server and Oracle. With either database, I would use a client-generated Guid for the primary key (which would map to uniqueidentifier in SQL Server, or RAW(20) in Oracle). Despite the performance penalty on

How to find the name and value of a table's primary key in DB2

不问归期 提交于 2019-12-02 01:50:46
问题 How can I find the primary key column name and value of a table? I have tried looking in the SYSCAT table but cannot find anything on this. 回答1: This should give you what you need on mainframe: http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNSQH11/E.8?DT=20010718164132 DB2 10 Z/OS: function: SQLPrimaryKeys() http://www.ibm.com/support/knowledgecenter/SSEPEK_10.0.0/odbc/src/tpc/db2z_fnprimarykeys.html 回答2: SELECT TBCREATOR, TBNAME, NAME, KEYSEQ FROM SYSIBM.SYSCOLUMNS WHERE

Custom PrimaryKey Generation with autoincrement

隐身守侯 提交于 2019-12-02 01:44:26
问题 I need to define and generate primary key for 2 or more tables. Tables hold same type of data but FOR Some BUSINESS RULES we have to make them separate say like TableA = LOCAL_CUSTOMERS TableB = INTERNATIONAL_CUSTOMERS Both hold same columns like, CUSTOMER_ID C_NAME, CITY ....etc While designing the Primary Key I want these keys to be a combination of PREFIX and an auto generated number, as an auto increamented int PK will do. for example, CUSTOMER_ID (PK) for the table "LOCAL_CUSTOMERS" LOC1

Custom PrimaryKey Generation with autoincrement

假如想象 提交于 2019-12-02 01:22:28
I need to define and generate primary key for 2 or more tables. Tables hold same type of data but FOR Some BUSINESS RULES we have to make them separate say like TableA = LOCAL_CUSTOMERS TableB = INTERNATIONAL_CUSTOMERS Both hold same columns like, CUSTOMER_ID C_NAME, CITY ....etc While designing the Primary Key I want these keys to be a combination of PREFIX and an auto generated number, as an auto increamented int PK will do. for example, CUSTOMER_ID (PK) for the table "LOCAL_CUSTOMERS" LOC1, LOC2, LOC3,...... LOC5000 and CUSTOMER_ID (PK) for the table "INTERNATIONAL_CUSTOMERS" INT1, INT2,

Meaning of @GeneratedValue with strategy of TABLE

左心房为你撑大大i 提交于 2019-12-02 01:13:25
The JPA specification gives the following explanation of the annotation @GeneratedValue(strategy=TABLE) : The TABLE generator type value indicates that the persistence provider must assign primary keys for the entity using an underlying database table to ensure uniqueness. But what does "using an underlying database table" mean in practice? Does it mean using an auxiliary table? Or by scanning the entity-table to find an ID not in use? Or something else? Check out JavaDoc for TableGenerator , it has a nice example of how it works: Example 1: @Entity public class Employee { ... @TableGenerator(

Oracle Materialized Views with primary key

和自甴很熟 提交于 2019-12-02 00:40:29
I created the Oracle Materialized View below: CREATE MATERIALIZED VIEW MyMV REFRESH COMPLETE ON DEMAND AS SELECT t1.* FROM table1 t1, table2 t2 where t1.id=t2.id; The table1 has a primary key and the MV was created succesfully but the primary key was not created in the materialized view table. Is there any other way to create MVs with primary keys? it's because your materialized view is based on two tables, if you create your view based on a single table with a primary key, then the primary key is created on you Materialized view. You can still create the index afterwards if you need one: SQL>

Primary key value after insertion of row in SQL Server 2005

老子叫甜甜 提交于 2019-12-02 00:11:00
问题 In SQL Server 2005 I am inserting a row into a table using a stored procedure and I want to fetch the new primary key value just after inserting that row. I am using following approach to get primary key value after insertion row Create Proc Sp_Test @testEmail varchar(20)=null,-- Should be Unique @testName varchar(20)=null -- Should be Unique as begin insert into tableTest (testUserEmail,testUserName)values (@testValue,@testName) select MAX(ID) from tableTest --ID is Primary Key --or select