[sql] qwerty
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- CREATE TABLE Authors (
- author_id INT PRIMARY KEY AUTO_INCREMENT,
- author_name VARCHAR(255)
- );
- CREATE TABLE Categories (
- category_id INT PRIMARY KEY AUTO_INCREMENT,
- category_name VARCHAR(255)
- );
- CREATE TABLE Documents (
- document_id INT PRIMARY KEY AUTO_INCREMENT,
- title VARCHAR(255),
- content TEXT,
- author_id INT,
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
- modified_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- FOREIGN KEY (author_id) REFERENCES Authors(author_id)
- );
- CREATE TABLE Documents_Categories (
- document_id INT,
- category_id INT,
- FOREIGN KEY (document_id) REFERENCES Documents(document_id),
- FOREIGN KEY (category_id) REFERENCES Categories(category_id)
- );
- -- Додати автора
- INSERT INTO Authors (author_name) VALUES ('John Doe');
- -- Додати категорію
- INSERT INTO Categories (category_name) VALUES ('Технології');
- -- Додати документ
- INSERT INTO Documents (title, content, author_id) VALUES ('Посібник з SQL', 'Це документ про SQL.', 1);
- -- Додати зв'язок між документом і категорією
- INSERT INTO Documents_Categories (document_id, category_id) VALUES (1, 1);
- SELECT Documents.title, Documents.content
- FROM Documents
- JOIN Documents_Categories ON Documents.document_id = Documents_Categories.document_id
- WHERE Documents_Categories.category_id = 1;
- -- Оновити зміст документу з ідентифікатором 1
- UPDATE Documents
- SET content = 'Це оновлений зміст документа.'
- WHERE document_id = 1;
Editor
You can edit this paste and save as new: