Answer the question
In order to leave comments, you need to log in
Does an UPDATE or DELETE on the "users" table violate the "posts_authorid_fkey" foreign key constraint on the "posts" table?
I create the users table:
CREATE TABLE users(
id UUID DEFAULT uuid_generate_v4(),
email TEXT,
name TEXT,
password TEXT,
PRIMARY KEY(id)
);
INSERT INTO users(id, email, name, password) VALUES('bdfe5653-f75a-42b4-93d2-f4f739c0bc7d', '[email protected]', 'Jone', 'somehashedpasswprd');
CREATE TABLE posts(
id uuid DEFAULT uuid_generate_v4(),
authorID uuid,
text TEXT,
FOREIGN KEY(authorID) REFERENCES users(id)
);
INSERT INTO posts(authorID, text)
VALUES('bdfe5653-f75a-42b4-93d2-f4f739c0bc7d', 'Post description I wrote the post for demonstation how I can use of sql');
ALTER TABLE posts
DROP CONSTRAINT authorID;
ALTER TABLE posts
ADD CONSTRAINT authorID
FOREIGN KEY(authorID)
REFERENCES users(id)
ON DELETE CASCADE
ON UPDATE CASCADE;
DELETE FROM users WHERE id = 'bdfe5653-f75a-42b4-93d2-f4f739c0bc7d'';
Answer the question
In order to leave comments, you need to log in
ALTER TABLE posts
DROP CONSTRAINT authorID;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question