0% found this document useful (0 votes)
13 views

DB SQL 1

The document contains SQL statements for creating, inserting, updating, and deleting data from recipes and categories database tables. It defines the schema and performs basic CRUD operations.
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)
13 views

DB SQL 1

The document contains SQL statements for creating, inserting, updating, and deleting data from recipes and categories database tables. It defines the schema and performs basic CRUD operations.
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 recipes( id INTEGER PRIMARY KEY, title VARCHAR(50) NOT NULL ,

content TEXT DEFAULT "Hello", slug VARCHAR(50) NOT NULL UNIQUE, duration
SMALLINT, online BOOLEAN, created_at DATETIME);*//*INSERT INTO recipes ( title,
slug, content, duration, online, created_at ) VALUES ( "soupe",
"legumineuse", "contenu de test", 20, TRUE, 1696673168 ), (
"soupe2", "legume", "contenu de test", 20, TRUE, 1696673168 ),
( "soupe3", "legume", "contenu de test", 20, TRUE, 1696673168
);*//* CREATE TABLE recipes ( id INTEGER PRIMARY KEY AUTOINCREMENT, title
VARCHAR(50), content TEXT, slug VARCHAR(50), duration SMALLINT, online
BOOLEAN, created_at DATETIME );*/-- UPDATE recipes set slug="legume4" where
id =6-- CREATE UNIQUE INDEX idx_slug ON recipes (slug)-- DROP TABLE recipes/*INSERT
INTO recipes ( title, slug, duration, online, created_at ) VALUES (
"soupe2", "legume3", 20, TRUE, 1696673168 );*/ /*PRAGMA foreign_keys =
on;DROP TABLE if EXISTS recipes;DROP TABLE if EXISTS categories;CREATE TABLE
categories ( id integer PRIMARY KEY AUTOINCREMENT, title VARCHAR(150) NOT
NULL, description TEXT );INSERT INTO categories (title) VALUES ("Plat"),
("Dessert");CREATE TABLE recipes ( id INTEGER PRIMARY KEY AUTOINCREMENT,
title VARCHAR (150) NOT NULL, slug VARCHAR(50) not NULL UNIQUE, content
TEXT, categories_id INTEGER, FOREIGN KEY (categories_id) REFERENCES categories(id)
ON DELETE SET NULL ); INSERT INTO recipes (title, slug, categories_id)
VALUES ("cr�me anglaise", "creme-anglaise",2), ("soupe","soupe",1),
("salade de fruit", "salade-de-fruit",2); */ /*SELECT recipes.id,
recipes.title AS "Nom de la recette", categories.titleFROM recipesJOIN categories
on recipes.categories_id = categories.id;*//*DELETE FROM categories where id=2;
SELECT *from recipes;SELECT *FROM categories;*/

You might also like