0% found this document useful (0 votes)
20 views1 page

CREATE TABLE Comments

The document creates tables for comments, articles, users, tags and articles_tags and defines primary and foreign keys for the tables to link them together.

Uploaded by

Iustin Ivan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

CREATE TABLE Comments

The document creates tables for comments, articles, users, tags and articles_tags and defines primary and foreign keys for the tables to link them together.

Uploaded by

Iustin Ivan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

CREATE TABLE comments

(
id NUMBER NOT NULL,
article_comment VARCHAR(200),
idarticle NUMBER NOT NULL,
iduser NUMBER NOT NULL
);

CREATE TABLE articles


(
id NUMBER NOT NULL,
iduser NUMBER NOT NULL,
title VARCHAR(50),
content VARCHAR(2000)
);

CREATE TABLE users


(
id NUMBER NOT NULL,
username VARCHAR(20),
password VARCHAR(50)
);

CREATE TABLE tags_articles


(
idarticle NUMBER NOT NULL,
idtag NUMBER NOT NULL
);

CREATE TABLE tags


(
id NUMBER NOT NULL,
tagname VARCHAR(30)
);

ALTER TABLE comments ADD CONSTRAINT pk_comments PRIMARY KEY (id);


ALTER TABLE articles ADD CONSTRAINT pk_articles PRIMARY KEY (id);
ALTER TABLE users ADD CONSTRAINT pk_users PRIMARY KEY (id);
ALTER TABLE tags ADD CONSTRAINT pk_tags PRIMARY KEY (id);
ALTER TABLE tags_articles ADD CONSTRAINT pk_tags_articles PRIMARY KEY (idarticle,
idtag);

ALTER TABLE comments ADD CONSTRAINT fk_comm__users FOREIGN KEY (iduser) REFERENCES
users(id);
ALTER TABLE comments ADD CONSTRAINT fk_comm__articles FOREIGN KEY (idarticle)
REFERENCES articles(id);
ALTER TABLE articles ADD CONSTRAINT fk_articles__users FOREIGN KEY (iduser)
REFERENCES users(id);
ALTER TABLE tags_articles ADD CONSTRAINT fk_tag_articles__articles FOREIGN KEY
(idarticle) REFERENCES articles(id);
ALTER TABLE tags_articles ADD CONSTRAINT fk_tag_articles__tags FOREIGN KEY (idtag)
REFERENCES tags(id);

DESC articles; DESCRIBE


SELECT constraint_name FROM all_constraints WHERE table_name = 'ARTICLES'; NEAPARAT
LITERE MARI LA NUME TABEL

You might also like