Questions tagged [primary-key]
In relational database design, a primary key can uniquely identify each row in a table. A primary key comprises a single column or a set of columns.
688 questions
1
vote
1
answer
107
views
Null value does not violate FOREIGN KEY constraint?
I am wondering why Postgres allows to insert a non-existing values for a foreign key to a nullable multicolumn unique constraint. (Cannot be an actual primary key.)
I made a fiddle. I expected this to ...
3
votes
2
answers
169
views
Primary Key creation for duplicate tables living on separate machines, in Postgres
I'm building out a data warehouse system in PostgreSQL that will be replicated across several machines. Each machine will read and write to its respective database, independent of the other machines ...
2
votes
1
answer
333
views
Change Tracking and Primary keys
I have a SQL Server database with Change Tracking enabled on a hand full of tables and it's used by another application on the cloud to sync data between both databases.
When an existing customer ...
1
vote
1
answer
81
views
For two oracle tables is it possible to keep their primary keys in separate integer ranges?
For two Oracle database tables in the same schema,
is it possible to keep their primary keys totally separate, so that an integer representing a primary key would appear in at most one of these tables?...
1
vote
0
answers
64
views
Foreign key does not appear in table structure in PHPMYADMIN
I am creating two tables called customer and item.
For the customer table customerID is the primary key and for the item table itemID is the primary key. And I am creating another table which is ...
0
votes
0
answers
60
views
Why does Postgresql use a Seq Scan on the first column of the PK?
This is my table:
CREATE TABLE IF NOT EXISTS public.ob_samples_sc5555 (
stamp timestamp(6) with time zone NOT NULL,
oblvl smallint NOT NULL,
olots integer NOT NULL,
CONSTRAINT ...
0
votes
1
answer
62
views
I should let the user type the primary key?
I have a Products table, 2 options:
Let the user type the PK because some users can input Barcodes or no (in this case, the app will let to user free to input anything for example his own code ...
4
votes
1
answer
268
views
Foreign Key join elimination working in one query but not in the other one?
In AdventureWorks2016 when I execute the following query:
USE AdventureWorks2016
BEGIN TRAN;
SELECT
Sales.SalesOrderHeader.SalesOrderID
FROM
Sales.SalesOrderHeader
JOIN
Sales.Customer
...
0
votes
1
answer
44
views
How to design properly a membership history accross multiple groups?
I'm looking to design an application (Python with sqlite) which deals with some contributors moving across several groups through time.
My design looks currently like (PK in bold weight, FK in italic, ...
0
votes
1
answer
108
views
Primary key constraint
I have few questions related to primary key in a table
I have a table with id as identity column and it is set as primary key
and also it created as clustured index by default
I want to remove the ...
0
votes
5
answers
204
views
Log table without primary key
I have a SQL Server log table that includes a column "Id"
This is an identity column, but not a primary key, it is not even indexed.
This would have just been set up from some tutorial for ...
3
votes
2
answers
581
views
Is there any benefit to declaring an index that contains a primary key as unique?
Suppose that I have a table with many columns that I don't care about, but two that I do: Primary and Secondary. There is a clustered primary key on Primary.
CREATE TABLE [dbo].[...
0
votes
0
answers
109
views
Is it a good idea to use time as primary key component?
I have a log/audit table which the only index I will ever use is time window.
Is it a good idea to PRIMARY KEY it as:
CREATE TABLE events (
created TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT NOW(...
1
vote
1
answer
439
views
How to attach partition with primary key
I'm struggling to attach a partition to a table with a primary key.
I have a partitioned table Transactions:
create table "Transactions"
(
id bigserial ...