Professional Documents
Culture Documents
name VARCHAR(128),
email VARCHAR(128)
);
SELECT * FROM Users WHERE email = 'PriceIs@rite.edu'; (To see one record in the table)
SELECT COUNT (*) FROM Users WHERE email = 'Lovey@bags.edu'; (COUNT ROWS WITH
SELECT)
SELECT * FROM Users WHERE name LIKE ‘%e%’; (This means show me all the entries that
have ‘e’ in their names.)
DATA TYPES
STRING FIELD
CHAR – ALLOCATES THE ENTIRE SPACE (FASTER FOR SMALLER STRINGERS WHERE THE
LENGTH IS KNOWN)
TEXT FIELD
Have a CHARACTER SET - If you are inserting a paragraph, a blog or a facebook post, etc,
then you would use one of the following:
TINYTEXT – UP TO 255 CHARACTERS
TEXT – UP TO 65K CHARACTERS
MEDIUM TEXT – UP TO 16M
LONGTEXT – UP TO 4GIGABYTES
BINARY TYPES
Characters = 8-32 bits of information depending on the character set.
BYTE (n) = UP TO 255 BYTES
VARBINARY (n) = UP TO 65K BYTES
Large raw data, files, images, word documents, PDFS, movies, etc
No translation, character set or indexing
TINYBLOB – UP TO 255
BLOB – UP TO 65K
MEDIUMBLOB – UP TO 16M
LONGBLOB – UP TO 4G
INTEGER NUMBERS
They are very efficient, take little storage, and are very easy to process because CPUs can
usually compare them with a single instruction. They are used for comparing, sorting and
indexing.
TINYINT – (-128,128)
FLOAT
They can represent a wide range of values, but accuracy is limited. They measure temperature,
etc.
DATES
TIMESTAMP – This is only limited to time between the years 1970 and 2037. ‘YYYY-MM-DD HH:MM:SS’
DATETIME – This can facilitate any time from any year. ‘YYYY-MM-DD HH:MM:SS’
DATE - ‘YYYY-MM-DD’
TIME – ‘HH:MM:SS’
Built in MySQL function NOW ()
AUTO-INCREMENT
Often when we make multiple tables and need to join them, we use an integer primary key for each
row so that we can efficiently add a reference to a row in some other table as a foreign key.
name VARCHAR(128),
email VARCHAR(128),
INDEX (email)
);
INSERT INTO Album (title, artist_id) VALUES ('The Lion King', 2);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('Hold up', 10, 230, 0, 1,
1);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('Sorry', 10, 300, 0, 1, 1);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('All Night', 10, 240, 0,
1, 1);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('Transformation', 10,
310, 0, 1, 1);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('Brown Skin Girl', 10,
230, 0, 2, 1);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('Spirit', 10, 230, 0, 2, 1);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('Return to Pride Rock',
10, 230, 0, 2, 1);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('The King', 10, 230, 0,
2, 1);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('What's my name', 10,
230, 0, 3, 2);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('Skin', 10, 230, 0, 3, 2);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('California King bed',
10, 230, 0, 3, 2);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('Only girl', 10, 230, 0, 3,
2);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('Kiss it better', 10, 230,
0, 3, 1);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('James Joint', 10, 230,
0, 3, 1);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('Consideration', 10,
230, 0, 3, 1);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('Higher', 10, 230, 0, 3,
1);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('High School', 10, 230,
0, 1, 2);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('Moment for Life', 10,
230, 0, 1, 2);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('Roman Holiday', 10,
230, 0, 1, 2);
INSERT INTO Track (title, rating, len, count, album_id, genre_id) VALUES ('Knock Out', 10, 230, 0,
1, 2);
select DISTINCT Artist.name, Genre.name from Track join Genre join Album join Artist on
Track.genre_id = Genre.genre_id and Track.album_id = Album.album_id and Album.artist_id =
Artist.artist_id where Artist.name = 'Beyonce'