Questions tagged [primary-key-design]

83 questions
1
vote
2 answers

Best way to create unique identities for distributed data that will be merged?

I have a centrally hosted database (MS SQL Server) and distributed clients save data to it over the Internet. When the Internet connection goes down the client starts storing new data locally into a SQLite instance. When the Internet connection…
John K
  • 28,441
  • 31
  • 139
  • 229
1
vote
3 answers

Primary Key and Composite Key

If we have a table whose primary key is a Composite Key, do we always create a new column as a primary key instead of the composite key?, or it depends on DB Analysis? Which way is the best? And why?
1
vote
2 answers

Increasing a +1 to the id without changing the content of a column

I have this random table with random contents. id | name| mission 1 | aaaa | kitr 2 | bbbb | etre 3 | ccccc| qwqw 4 | dddd | qwert 5 | eeee | potentials 6 | ffffffff | toto What I want is to add in the above table a column with id=3 with…
1
vote
2 answers

Should primary key be used on a table that has only 2 columns, both are unique

If I have a table like the Following CustomerAddress(CustomerId, AddressId) Would I still need an additional primary key, e.g., int auto increment? Or would setting both the columns as primary keys be sufficient? ASSUMPTION: When deleting, I will…
0
votes
0 answers

ETL process where Primary Unique key changes after order status change

I have an ETL process I'm building and I'm trying to figure out the best way to build it. For context, i'm working with retail orders related data at a distribution center, so these orders start with an "open" status, meaning orders that need to be…
0
votes
3 answers

MYSQL - Problems using a string as primary key

Possible Duplicate: Alphanumeric Order By in Mysql My tables are sorting my records incorrectly. The primary key is a string that as one char and its combined with a number starting from 1 ex: F1. It becomes problematic when it got to two digit…
Helio
  • 1
  • 3
0
votes
1 answer

SQL Server use same Guid as primary key in 2 tables

We have 2 tables with a 1:1 relationship. 1 table should reference the other, typically one would use a FK relationship. Since there is a 1:1 relationship, we could also directly use the same Guid in both tables as primary key. Additional info: the…
0
votes
1 answer

JSON object with id as primary key schema design

I want to use an ID as the primary key in a JSON object. This way all users in the list are unique. Like so: { "user": [{ "id": 1, "name": "bob" }] } In an application, I have to search for the id in all elements of the…
adrian
  • 13
  • 1
0
votes
3 answers

optomise very large table query

I have a table that is close to 20million records and growing. The table was setup as innodb. There is a primary index on the two main fields: `entries_to_fields` entry_id int(11) NO PRI NULL field_id int(11) NO PRI NULL value …
Ben Rowe
  • 28,406
  • 6
  • 55
  • 75
0
votes
0 answers

SQL Server Removing Duplicate Rows & Managing Keys

I have two tables as shown below. The Transaction Table is a table representing a sales event between a Buyer and a Supplier. The ... in the table represents other columns such as TransactionDate, Store Information, etc. The Contact Table is a table…
M. Stolte
  • 105
  • 1
  • 1
  • 11
0
votes
1 answer

Create a Primary Key on a large table (6Million records) without locking the table in PostgreSQL

I want to create a Primary Key on a table with 6 Million records, but when I execute this: ALTER TABLE schema_name.table_name ADD CONSTRAINT pkey_name PRIMARY KEY (field_pkey_name); It's locking my table and alter table does not finish executing...
davidleongz
  • 155
  • 2
  • 11
0
votes
0 answers

Can a CLR UDT be a PK on a table?

Can you have your own clr udt as a primary key on a table? It seems you cannot - I added interfaces for binary serialization and comparable, but when using the type in a PK Constraint I receive an error: The type cannot be used in a primary key. So…
Ralf
  • 538
  • 1
  • 6
  • 17
0
votes
1 answer

Can I use Elegant Pairing Function as primary key in DB?

I'm writing a server that allows multiple users can modify a post. So I created Permission table that contains user id, post id, and permission data. And I just wanted to query this with only one value (I just thought that querying with one value is…
Lee M.U.
  • 123
  • 1
  • 12
0
votes
0 answers

Primarykey handling on n:m relationships with identifying parent relationship?

Watch this example for an identifying relationship between project and bug: MySQL Workbench creates on identifying relationships not a single primarykey like bug.id for table bug. The primary key in this case consist of bug.id and bug.project_id…
Mike
  • 161
  • 1
  • 12
0
votes
1 answer

SQL Unique Key iff not Deleted

I have table as below: +----------+---------+ | ParentId | ChildId | +----------+---------+ It is a one-to-many relationship (one parent, multiple children) at the moment the primary key is the child id because a child can only map to one parent…
Heinrich
  • 2,144
  • 3
  • 23
  • 39