· 8 years ago · May 18, 2018, 03:10 PM
1#set the environment
2SET SQL_MODE = 'STRICT_ALL_TABLES';
3
4#drop database if it exists - BEWARE
5DROP DATABASE IF EXISTS db_drinks;
6
7#re-create a database
8CREATE DATABASE db_drinks;
9
10#use the database
11USE db_drinks;
12
13#create a table to store student information
14CREATE TABLE tbl_infodrinks
15(
16 drinkname VARCHAR(18) NOT NULL,
17 cost DECIMAL(3,2) UNSIGNED NOT NULL,
18 carbs DECIMAL(4,2) UNSIGNED NOT NULL,
19 color VARCHAR(8) NOT NULL,
20 ice ENUM('Y','N') NOT NULL,
21 calories TINYINT UNSIGNED NOT NULL
22);
23
24#populate the table with drinks data
25#by default every row/record needs 6 values in the order of the fields/columns/attributes
26#as defined in the CREATE TABLE command
27
28INSERT INTO tbl_infodrinks(drinkname,cost,carbs,color,ice,calories)
29VALUES
30('Blackthorn',3,8.4,'Yellow','Y',33),
31('Blue Moon',2.50,3.2,'Blue','Y',12),
32('Oh My Gosh',3.50,8.61,'Orange','Y',35),
33('Lime Fizz',2.50,5.4,'Green','Y',24),
34('Kiss on the Lips',5.50,42.52,'Purple','Y',171),
35('Hot Gold',3.20,32.1,'Orange','N',135),
36('Lone Tree',3.60,4.2,'Red','Y',17),
37('Greyhound',4.5,14,'Yellow','Y',50),
38('Indian Summer',2.80,7.2,'Brown','N',30),
39('Bull Frog',2.60,21.5,'Tan','Y',80),
40('Soda and It',3.80,4.7,'Red','N',19);
41
42#select all the columns(*) and rows from the table
43SELECT * FROM tbl_infodrinks;