Questions tagged [primary-key-design]

83 questions
2
votes
2 answers

crc32 of natural key as a primary key

I have a database of TCG cards and I am trying to decide a primary key. I settled with a surrogate key initially but I realized that sometimes, there are cards that I forget to add, like promo cards for example. This is problematic with the…
voldomazta
  • 1,300
  • 1
  • 10
  • 19
2
votes
3 answers

Primary Key Index Automatic

I m currently doing a project using mysql and am a perfect beginner in it..... I made a table with the following columns..... ID // A integer type column which is a primary key........ Date // A Date type…
Arjun K P
  • 2,081
  • 4
  • 20
  • 33
1
vote
1 answer

Access VBA avoiding a conflict with primary key when adding a record to a linked table

So the root of this problem may lie in poor database design, some of the way this is set up is inherited from older versions. I just couldn't figure out a better way to do this. I have four tables linked by the same field: [OBJECTID]. Each table is…
mizmay
  • 11
  • 1
1
vote
2 answers

SQL tables primary key

which is better to be used Guid Or Int Primary Key? some search result favors Guid and other favor Int. so what are really the pros and cons of each.
SShebly
  • 2,043
  • 1
  • 21
  • 29
1
vote
1 answer

How to create a Custom Unique Primary Key using prisma?

In my application i want to create a default primary key where the key must start with BL- and another rest 9 digits character must be random. Schema model myModel { // try 1 id String @id @default(dbgenerated("BL-")) // try 2 id  String @id…
1
vote
1 answer

Extension of an ID based off the ID of another table

I have two tables. Order and Pallet. Each order can have several pallets. I am trying to figure out if I can make the PalletID an extension of the OrderID. For example there is an OrderID of 8000. When a pallet is added to the order the palletID…
1
vote
3 answers

MySQL. Primary key in a relational table. Unique id or multiple unique key?

Primary key in relational tables. Composite primary key or unique primary key in those pure relational tables? Which design would you recommend to use in MySQL for high performance? See diagram Technical advantages and disadvantages! Thanks…
1
vote
2 answers

Skipping perfectly identical records in SQL Server

I have a set of text files I'm importing into SQL Server via a SqBulkCopy in C#. There are some records that appear in multiple records and I'd like to skip those rather than throwing an error and stopping. For cases where there's a clear…
Glinkot
  • 2,924
  • 10
  • 42
  • 67
1
vote
1 answer

Output Inserted or deleted in SQL Server

I have a SalesTransaction and an Invoice table: Create Table SalesTransaction ( SalesTransactionId int Identity(1,1) Primary Key, CustomerId int Foreign key references Customer(CustomerId) , ProductId int Foreign key references…
Melina Sharma
  • 130
  • 1
  • 8
1
vote
1 answer

Allocate ranges of primary key integers

Given RangeA of auto-incrementing primary key integers (1 to 32767) and RangeB (32768 to 2147483647). If a condition is true, save an object with a primary key assigned in RangeA, else save it in RangeB. The admin (me) would be the only user saving…
davidtgq
  • 3,780
  • 10
  • 43
  • 80
1
vote
1 answer

Correct structure and index for a Weekly table

I need a table to store text every week for each user. So I thought two alternatives: 1) Using composite primary key: CREATE TABLE `WeeklyTxt` ( `Year` YEAR(4) NOT NULL , `Week` ENUM('1','2','3','4', ... ,'51','52','53') NOT NULL , `UserId` BIGINT…
genespos
  • 3,211
  • 6
  • 38
  • 70
1
vote
1 answer

ASP MVC code first create computed primary key

I am using code first in asp mvc and i came across a situation where i need to have a model/table with a computed primary key for example: public class Student { [Key] public string StudentNumber { get; set; } public string FirstName {…
JustLearning
  • 3,164
  • 3
  • 35
  • 52
1
vote
1 answer

Generate column value automatically from other columns values and be used as PRIMARY KEY

I have a table with a column named "source" and "id". This table is populated from open data DB. "id" can't be UNIQUE, since my data came from other db with their own id system. There is a real risk to have same id but really different data. I want…
Lionel
  • 90
  • 1
  • 9
1
vote
1 answer

SQLAlchemy sheme that allows two tables to share a primary key column

Say I have two tables, foo and bar. Both have primary keys. I want to set it up in SQLAlchemy so that the combined set of foo.id and bar.id is unique. How would I do that? I tried adding another table containing only the primary keys and having…
Niel
  • 1,856
  • 2
  • 23
  • 45
1
vote
2 answers

No two rows of different tables have same primary key?

One of my tables order has one to many relationship with two other tables PaymentMethod1 and PaymentMethod2. I have created separate "payment method" tables since they have completely different attributes so that I can avoid nulls. But, a particular…