How to store a chat in a mysql db

From: ^Bart <gabriele1NOSPAM_at_hotmail.com>
Date: Tue, 19 Mar 2019 09:59:51 +0100
Message-ID: <q6qb29$omc$1_at_gioia.aioe.org>



I need to add a chat for the users of my db, I found on internet this link https://stackoverflow.com/questions/3094495/db-schema-for-chats but I don't know if it's the best solutions...

I managed that "idea" for my DB:

CREATE TABLE chats
(
id_chat INT(7) UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY (id_chat)
)
ENGINE=INNODB; CREATE TABLE chat_users
(
id_chat_user INT(7) UNSIGNED NOT NULL AUTO_INCREMENT, FK_id_user INT(25) NOT NULL,
PRIMARY KEY (id_chat_user),
INDEX (FK_id_user),
FOREIGN KEY (FK_id_user)
REFERENCES users (id_user)
)
ENGINE=INNODB; CREATE TABLE chat_lines
(
id_chat_line BIGINT(7) UNSIGNED NOT NULL AUTO_INCREMENT,
`chat_id` INT UNSIGNED NOT NULL,
`user_id` INT UNSIGNED NOT NULL,
`line_text` INT UNSIGNED NOT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY (id_chat_line) ,

INDEX `fk_chat_line_chat` (`chat_id` ASC) ,
INDEX `fk_chat_line_chat_user1` (`user_id` ASC) ,
CONSTRAINT `fk_chat_line_chat`

FOREIGN KEY (`chat_id`)
REFERENCES `chats` (`id_chat`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_chat_line_chat_user1`
FOREIGN KEY (`user_id`)
REFERENCES `chat_users` (`id_chat_user`) ON DELETE NO ACTION
ON UPDATE NO ACTION)
)
ENGINE=INNODB; [Quoted] In the third table I have: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') ENGINE=INNODB' at line 21

It seems everything is ok... :\

^Bart Received on Tue Mar 19 2019 - 09:59:51 CET

Original text of this message