clear markdown compare help donate or buy diddy dollings comments/suggestions/bugs a leap of faith? bible365
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 756542 fiddles created (13503 in the last week).

SELECT * FROM version();
version
PostgreSQL 12.0 (Debian 12.0-1.pgdg90+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit
 hidden batch(es)


CREATE TABLE user_ ( user_id INTEGER NOT NULL PRIMARY KEY, user_name VARCHAR (25) NOT NULL );
 hidden batch(es)


INSERT INTO user_ (user_id, user_name) SELECT 1, 'user_1' UNION SELECT 2, 'user_2';
2 rows affected
 hidden batch(es)


SELECT * FROM user_ ORDER BY user_id;
user_id user_name
1 user_1
2 user_2
 hidden batch(es)


CREATE TABLE message ( message_id INTEGER NOT NULL PRIMARY KEY, sender_id INTEGER, message_text VARCHAR (100) NOT NULL, FOREIGN KEY (sender_id) REFERENCES user_ (user_id) );
 hidden batch(es)


INSERT INTO message SELECT 1, 1, 'm1' UNION SELECT 2, 1, 'm2' UNION SELECT 3, 2, 'm3' UNION SELECT 4, 2, 'm4';
4 rows affected
 hidden batch(es)


SELECT * FROM message ORDER BY message_id;
message_id sender_id message_text
1 1 m1
2 1 m2
3 2 m3
4 2 m4
 hidden batch(es)


INSERT INTO message VALUES (5, 56, 'mxxxx');
ERROR: insert or update on table "message" violates foreign key constraint "message_sender_id_fkey" DETAIL: Key (sender_id)=(56) is not present in table "user_".
 hidden batch(es)