All Questions
Tagged with composite-primary-key sql
203 questions
1
vote
1
answer
40
views
One of the Multiple Columns Primary Key is Inferred from another because of ORDER BY request
Context
I have a table T with its primary key containing multiple columns:
A, B, C, D
Use Cases
This table may contains millions of rows.
And there are two constraints:
Reading fast using an ORDER BY ...
-1
votes
1
answer
59
views
Create Key using two columns and do a left join SQL
I have two tables I would to do a left join on.
Order:
| ID | CATA | Repo | Assc |
Return:
| ID | CATB | Addl| Sumin|
I need to create a Key using ID+CATA on Order table and ID+CATB on Return Table. ...
0
votes
0
answers
55
views
Unexpected outcome of the "before insert" triger with subquery and EXISTS predicate along with further PK violation
I am managing a legacy web-app which process data using Firebird 2.5-based DB (runs on Ubuntu 18.04 server). All was OK for years, but I got something very strange recently.
There is a table with ...
-2
votes
1
answer
76
views
What is the maximum column varchar size for Composite columns in Oracle
I am trying something like below and getting exception.
CREATE TABLE test1( col1 varchar(4000) NOT NULL, col2 varchar(4000) NOT NULL, col3 varchar(4000), col4 varchar(4000), col5 varchar(4000) NOT ...
0
votes
1
answer
66
views
Assign a Resetting Per-Parent Incrementing Column to Each Child Record
I have two tables, a SalesOrderHeader that has an identity primary key TxnID column and a TxnNumber column that I obtain from external software. For example sake I will omit any other columns and lets ...
0
votes
1
answer
465
views
OLAP Data Warehouse - composite primary key as multiple or single fields
I'm building a data warehouse, and the data is of a quality where 8 fields may be required to uniquely identify a record, and this applies to three tables, each of which will have a few million rows ...
0
votes
1
answer
1k
views
How best to update row where composite primary key values change
We have numerous tables where we have composite keys with MULTIPLE entries. In some cases as many as SIX values that make up the primary key for a table that is not super large, maybe a few thousand ...
0
votes
0
answers
762
views
Trying to create a Composite Primary Key in MSSQL with only a part of 2 columns
I'm new to SQL and am following a course, however it does not cover the "create table" part.
It only covers statements etc.
What I would like to have is, my primary key (cust_id) to be ...
-1
votes
2
answers
317
views
Is there a way to generate composite key efficiently in a PostgreSQL database?
Suppose I have a student table with id as primary key, which holds information about all students.
id | name
---+------
1 | aaron
2 | bob
In addition there is a table where id and tid form a ...
0
votes
3
answers
3k
views
where clause with composite primary key
For example I have a composite primary key on columns id, age in the following table:
id
age
name
1
23
John
2
24
Alex
3
22
Rob
4
20
Ella
can I somehow query the table using composite primary key in ...
0
votes
1
answer
53
views
How to create a table such that when ever a record is inserted, composite key values gets inserted in another column?
I could find many methods to create a unique composite key while creating a table. But I was unable to figure out how i can create a column that contains composite key values automatically whenever a ...
0
votes
1
answer
237
views
Expressing identifying and non-identifying relationships in MySQL
Context
I'm learning about identifying and non-identifying relationships, and I'm wondering how I'd express them in MySQL. For practice, I've been working on a database for Pokemon. For context, every ...
0
votes
2
answers
1k
views
How to efficiently store tags for items in relational database?
Generally speaking, is making all attributes in an entity a concat PK possible, or is it a bad practice? A product may have many tags and how do I store these tags for each product? Is it possible to ...
0
votes
1
answer
2k
views
Constraint "PK" of relation "table" does not exist when generating migration with typeorm
I have an ormconfig.ts like this:
const config: ConnectionOptions = {
type: "postgres",
host: "localhost",
username: "postgres",
password: "postgres",
...
0
votes
0
answers
114
views
Database; 2NF to 3NF questions about (Primary) Keys
I'm currently learning about databases and 1NF, 2NF and 3NF. So far 1NF is easy, but I get confused going to 2NF and 3NF regaring Primary Keys and foreign keys.
I've read a lot of posts on here but I ...