Skip to content

Instantly share code, notes, and snippets.

@thomasthaddeus
Created August 4, 2022 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasthaddeus/85ac2ff4bca346928610743f3945180a to your computer and use it in GitHub Desktop.
Save thomasthaddeus/85ac2ff4bca346928610743f3945180a to your computer and use it in GitHub Desktop.
Key Validation for DB design
CREATE TABLE book (
title varchar(100),
isbn varchar(50) PRIMARY KEY,
pages integer,
price money,
description varchar(256),
publisher varchar(100)
);
CREATE TABLE chapter (
id integer PRIMARY KEY,
number integer,
title varchar(50),
content varchar(1024)
);
CREATE TABLE author (
name varchar(50),
bio varchar(100),
email varchar(20) PRIMARY KEY
);
SELECT
constraint_name, table_name, column_name
FROM
information_schema.key_column_usage
WHERE
table_name = 'book';
SELECT
constraint_name, table_name, column_name
FROM
information_schema.key_column_usage
WHERE
table_name = 'chapter';
SELECT
constraint_name, table_name, column_name
FROM
information_schema.key_column_usage
WHERE
table_name = 'author';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment