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