-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateRecipeTables.sql
51 lines (40 loc) · 1.59 KB
/
CreateRecipeTables.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**********************************************************************
Author: Mikesh Mistry *
*
Description:SQL script to create the tables for the recipe database *
This is the second script to run in the series of scripts *
*
Date Created: 11/20/20 *
***********************************************************************/
/*Use the RecipeDB this assumes the first script to create the db was runned (CreateRecipeDatabase.sql) */
USE RecipeDB
/*Create the Recipe Table if it does not exist in RecipeDB */
IF OBJECT_ID('RecipeDB.dbo.Recipe') IS NULL
BEGIN
PRINT 'Creating Table Recipe'
CREATE TABLE dbo.Recipe
(
recipe_id INT NOT NULL IDENTITY(1,1),
name VARCHAR(MAX) NOT NULL,
description VARCHAR(MAX) NOT NULL,
instructions VARCHAR(MAX) NOT NULL,
PRIMARY KEY(recipe_id)
)
PRINT 'Table Recipe Created'
END
/* Recipe Table Exists */
ELSE
PRINT 'Recipe Table Exists'
/*Create the Ingredients Table if it does not exist in RecipeDB */
IF OBJECT_ID('RecipeDB.dbo.Ingredients') IS NULL
BEGIN
PRINT 'Creating Table Ingredients'
CREATE TABLE dbo.Ingredients
(
ingredient_id int NOT NULL IDENTITY (1, 1),
name varchar(MAX) NOT NULL,
description varchar(MAX) NOT NULL,
recipe_id int FOREIGN KEY REFERENCES Recipe(recipe_id)
)
PRINT 'Table Ingredients Created'
END