primary-key

How to alter length of varchar in composite primary key?

99封情书 提交于 2019-12-09 08:40:11
问题 In MSSQL I have a table created like this: CREATE TABLE [mytable] (fkid int NOT NULL, data varchar(255) CONSTRAINT DF_mytable_data DEFAULT '' NOT NULL); ALTER TABLE [mytable] ADD CONSTRAINT PK_mytable_data PRIMARY KEY (fkid, data); Now I want to increase the length of the 'data' column from 255 to 4000. If I just try: ALTER TABLE [mytable] ALTER COLUMN data varchar(4000); Then I get this error: The object 'PK_mytable_data' is dependent on the column 'data' If I try this: ALTER TABLE [mytable]

Using text as a primary key in SQLite table bad?

柔情痞子 提交于 2019-12-09 07:44:43
问题 Is it bad to have text as a primary key in an SQLite database? I heard that it's bad for performance reasons, is this true? And will the rowid be used as the actual primary key in such a case? 回答1: Is it bad to have text as a primary key in an SQLite database? I heard that it's bad for performance reasons, is this true? I never heard that somebody used string as primary key in table. For me (and I honestly hope also for others) very "ugly" practise with very low performance. If you'll use

Why primary key is (not) required on fact table in dimensional modelling?

China☆狼群 提交于 2019-12-09 04:26:20
问题 I have heard a few references that pk is not required on fact table. I believe every single table should have a pk. How could a person understand a row in a fact table if there is no pk and 10+ foreign keys. 回答1: Primary Key is there ... but Enforcing the primary key constraint in database level is not required. If you think about this, technically a unique key or primary key is a key that uniquely defines the characteristics of each row. And it can be composed of more than one attributes of

When would you use GUIDs as primary keys? [duplicate]

不打扰是莪最后的温柔 提交于 2019-12-09 04:25:37
问题 This question already has answers here : Closed 10 years ago . Possible Duplicate: Advantages and disadvantages of GUID / UUID database keys Are there any circumstances where it is essential to use GUIDs as primary keys in a SQL Server 2005/8 DB. For example, does the use of the MS Sync Framework force this, or data replication? 回答1: You would use guids as a key if you needed multiple databases synchronising via replication. Another reason to use guids is if you wanted to create rows on some

Composite DB keys with Entity Framework 4.0

ぐ巨炮叔叔 提交于 2019-12-09 02:35:00
问题 The re-design for a large database at our company makes extensive use of composite primary keys on the database. Forgetting performance impacts, will this cause any difficulties when working with this db in Entity Framework 4.0? The database structure is unlikely to change and I'm not looking for "philosophical" debate but what are the practical impacts? According to Jeremy Miller, "Composite key make any kind of Object/Relational mapping and persistance in general harder." but he doesn't

How to fix: Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information

℡╲_俬逩灬. 提交于 2019-12-08 21:38:42
问题 My code works. After I copy about 10 tables I get an error. Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information. Okay, I know I need to generate a primary key. But why can I copy 10 or so tables over, and THEN I get the error. Does each row have to return a primary key? If a row doesn't have a primary key, how do I generate one? Here is my code: using System; using System.Collections.Generic; using System.Data;

In JPA, having a many-to-one as primary key throws referential integrity constraint violation

痞子三分冷 提交于 2019-12-08 19:04:27
I have defined the following entities: @Entity public class Child implements Serializable { @Id @ManyToOne(cascade = CascadeType.ALL) public Parent parent; @Id public int id; } @Entity public class Parent { @Id public int id; } When I try to persist a Child with the following code: Parent p = new Parent(); p.id = 1; Child c1 = new Child(); c1.id = 1; c1.parent = p; em.persist(c1); Hibernate throws a 'Referential integrity constraint violation' error: Caused by: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "FK3E104FC802AAC0A: PUBLIC.CHILD FOREIGN KEY(PARENT_ID)

Insert an auto-incremented primary key into an Access table

北城以北 提交于 2019-12-08 17:36:10
问题 We have a giant table in an Access database with over 500k records and no PK. Is it possible to insert an auto-incrementing primary key column into an already existing Access table? 回答1: Yes, it is and can be done quite simply by editing the table and adding an autoincrement type field. The only rule is that you can only have one autoincrement per table. 来源: https://stackoverflow.com/questions/12609621/insert-an-auto-incremented-primary-key-into-an-access-table

PostgreSQL: is it possible to provide custom name for PRIMARY KEY or UNIQUE?

天大地大妈咪最大 提交于 2019-12-08 16:37:59
问题 When I write: CREATE TABLE accounts ( username varchar(64) PRIMARY KEY, I get primary key named: accounts_pkey Is it possible to assign my own custom name, for instance "accounts_primary_key"? Same story about UNIQUE . I couldn't find it in PostgreSQL documentation. Thanks in advance. 回答1: The trick is the CONSTRAINT part in the column_constraint section of CREATE TABLE . Example: > create table x(xx text constraint xxxx primary key); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit

MySQL unique id or combined id

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 15:13:17
问题 I have the following structure for my project and developer program: developer table id developer name etc... project table id project name etc... developer _project table ??? Because a developer can be in multiple projects and a projects can have multiple developer I have to create a new table but from what I read is they don't tell what id should I use. If I use an id auto increment + user_id + project_id will I have duplicate since the id is the primary key? 回答1: Use a unique combined key: