03.4: Create a Table in MySQL

In this lesson we look at the basics of how MySQL stores data.

How do we create a table, what are MySQL's column data types, how do we insert data into a table, and how do we read data from a table?


https://www.youtube.com/watch?v=c2BSiI9C7AU





# * MySQL basics
# * --------------------------------------------------------------

CREATE TABLE items (
	item_id int,
	item_name varchar(255),
	item_qty int
);


INSERT INTO items (item_id, item_name, item_qty) 
	   VALUES (1, "Brand X Printer Ink", 20);
SELECT * FROM items;



INSERT INTO items (item_id, item_name, item_qty) VALUES (2, "Printer Paper 20lb", 12);
INSERT INTO items (item_id, item_name, item_qty) VALUES (3, "Staplers", 0);


SELECT item_name, item_qty FROM items;


SELECT item_id, item_name, item_qty FROM items WHERE item_qty = 0;

	




# * --------------------------------------------------------------

CREATE TABLE users (
    user_id int not null auto_increment,
    name varchar(255),
    email varchar(255),
    password varchar(255),

    primary key (user_id)
);




INSERT INTO users (name, email, password) VALUES ("Jim Smith", "jim@fakemail.com", "12345");
INSERT INTO users (name, email, password) VALUES ("Jane Marsha", "jane@fakemail.com", "abcde");

# Never store passwords in clear text!



# To select records from a table
SELECT name, email, password FROM users;