Answer the question
In order to leave comments, you need to log in
How would this SQL syntax for PSTGRESQL look like in MARIADB?
I am new to databases, writing a program that runs on MariaDB.
There is SQL written for postgree, but I can't figure out how it should look like in maria
CREATE TABLE images (
image_id SERIAL PRIMARY KEY,
filename TEXT NOT NULL UNIQUE
);
CREATE TABLE tags (
tag_id SERIAL PRIMARY KEY,
tag TEXT NOT NULL UNIQUE
);
CREATE TABLE images_tags (
PRIMARY KEY (tag_id, image_id),
image_id INTEGER NOT NULL REFERENCES images (image_id),
tag_id INTEGER NOT NULL REFERENCES tags (tag_id)
);
Answer the question
In order to leave comments, you need to log in
This solution works in MariaDB:
CREATE TABLE images (
image_id INTEGER AUTO_INCREMENT PRIMARY KEY,
filename VARCHAR(255) NOT NULL UNIQUE
);
CREATE TABLE tags (
tag_id INTEGER AUTO_INCREMENT PRIMARY KEY,
tag VARCHAR(255) NOT NULL UNIQUE
);
CREATE TABLE images_tags (
image_id INTEGER NOT NULL,
tag_id INTEGER NOT NULL,
PRIMARY KEY (tag_id, image_id),
FOREIGN KEY (tag_id) REFERENCES tags(tag_id),
FOREIGN KEY (image_id) REFERENCES images(image_id)
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question