primary-key

How to save a UUID as binary(16) in java

无人久伴 提交于 2019-12-05 02:29:31
问题 I have a table TestTable with columns ID as binary(16) and name as varchar(50) I've been trying to store an ordered UUID as PK like in this article Store UUID in an optimized way I see the UUID is saved in database as HEX (blob) So I want to save this ID from java but I am getting this error Data truncation: Data too long for column 'ID' at row 1 I am currently using the library sql2o to interact with mysql So basically this is my code String suuid = UUID.randomUUID().toString(); String

Primary key and foreign key at the same time with doctrine 2

点点圈 提交于 2019-12-05 02:17:50
I have the two tables : table A with id as primary key table B with id as primary key and foreign key Explanation on short: I need to have in table B a primary key that also to be a foreign key that points to table A 's primary key. Can anybody explain me how to map this by annotations in Doctrine 2? Note: I tried it By this : class A { /** * @var bigint $id * * @Column(name="id", type="bigint", nullable=false) * @Id * @GeneratedValue(strategy="IDENTITY") */ private $a_id; ... and B table: class B { /** * @var bigint $id * @Id * @OneToOne(targetEntity="A", fetch="LAZY") * @JoinColumn(name="id"

Best approach for multi-tenant primary keys

旧城冷巷雨未停 提交于 2019-12-05 02:13:51
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 Tim Lentine Are you planning on using SQL Azure Federations in the future? If so, the current version of SQL Azure

JPA @OneToMany and composite PK

若如初见. 提交于 2019-12-05 02:10:55
I am working on a JPA project. I need to use a @OneToMany mapping on a class that has three primary keys. You can find the errors and the classes after this. javax.persistence.PersistenceException: No Persistence provider for EntityManager named JTA_pacePersistence: Provider named oracle.toplink.essentials.PersistenceProvider threw unexpected exception at create EntityManagerFactory: javax.persistence.PersistenceException javax.persistence.PersistenceException: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions

numeric(38,0) as primary key column; good, bad, who cares?

扶醉桌前 提交于 2019-12-05 00:46:10
On my current project, I came across our master DB script. Taking a closer look at it, I noticed that all of our original primary keys have a data type of numeric(38,0) We are currently running SQL Server 2005 as our primary DB platform. For a little context, we support both Oracle and SQL Server as our back-end. In Oracle, our primary keys have a data type of number(38,0). Does anybody know of possible side-effects and performance impact of such implementation? I have always advocated and implemented int or bigint as primary keys and would love to know if numeric(38,0) is a better alternative

Fluent NHibernate primary key constraint naming conventions

白昼怎懂夜的黑 提交于 2019-12-04 22:28:23
Is there any way to create a naming convention for my primary key constraints in Fluent NHibernate? I know you can name foreign key constraints, but it does not appear possible to name the primary key constraint. James Gregory from FNH says... No, that's not supported through NHibernate, so we can't support it either. http://groups.google.com/group/fluent-nhibernate/browse_thread/thread/9ea7155407d33772 来源: https://stackoverflow.com/questions/1358043/fluent-nhibernate-primary-key-constraint-naming-conventions

Create view with primary key?

冷暖自知 提交于 2019-12-04 22:27:07
I create a view with following codes SELECT CONVERT(NVARCHAR, YEAR(okuma_tarihi)) + 'T1' AS sno, YEAR(okuma_tarihi) AS Yillar, SUM(toplam_kullanim_T1) AS TotalUsageValue, 'T1' AS UsageType FROM TblSayacOkumalari GROUP BY CONVERT(NVARCHAR, YEAR(okuma_tarihi)) + 'T1', YEAR(okuma_tarihi) UNION ALL SELECT CONVERT(NVARCHAR, YEAR(okuma_tarihi)) + 'T2' AS sno, YEAR(okuma_tarihi) AS Yillar, SUM(toplam_kullanim_T2) AS TotalUsageValue, 'T2' AS UsageType FROM TblSayacOkumalari GROUP BY CONVERT(NVARCHAR, YEAR(okuma_tarihi)) + 'T1', YEAR(okuma_tarihi) UNION ALL SELECT CONVERT(NVARCHAR, YEAR(okuma_tarihi))

Primary key in cassandra is unique?

浪尽此生 提交于 2019-12-04 22:22:30
It could be kind of lame but in cassandra has the primary key to be unique? For example in the following table: CREATE TABLE users ( name text, surname text, age int, adress text, PRIMARY KEY(name, surname) ); So if is it possible in my database to have 2 persons in my database with the same name and surname but different ages? Which means same primary key.. Yes the primary key has to be unique. Otherwise there would be no way to know which row to return when you query with a duplicate key. In your case you can have 2 rows with the same name or with the same surname but not both. By definition

How can I get the auto incrementing field name or the primary key fieldname from a mysql table?

半世苍凉 提交于 2019-12-04 22:16:39
问题 In PHP, how do I get the field name of the field that's been set as to auto increment when a new rec is added to it? In most cases, it's the same as the PRIMARY_KEY of the table but not necessarily always. So this question has 2 parts with the second one branching into a 3rd part. 1- How to get the name of the auto-incrementing field name... 2- How to get the name of the primary_key field name... 2.1 How to get the primary_key(s) info when a table uses more than one field as its primary key..

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

孤人 提交于 2019-12-04 22:09:42
问题 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. 回答1: 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