If you don’t remember your database’s name, type SHOW DATABASES; to list the databases on the MySQL server. If you don’t have a database yet, you can create one by typing CREATE DATABASE database;. The database name cannot contain spaces.
INT - This data type is for whole numbers, and is often used for ID fields. DECIMAL - This data type stores decimal values, and is defined by the total number of digits and after the number after the decimal. For example: DECIMAL(6,2) would store numbers as “0000. 00”. CHAR - This is the basic data type for text and strings. You would normally define a limit for the number of characters stored, such as CHAR(30). You can also use VARCHAR to vary the size based on input. Phone numbers should also be stored using this data type, as they often contain symbols and do not interact with numbers (they are not added, subtracted, etc. )[1] X Research source . DATE - This data type stores dates in the format YYYY-MM-DD. Use this if you need to store someone’s age as opposed to their actual age, otherwise you will need to update the entry every year.
INT NOT NULL PRIMARY KEY AUTO_INCREMENT creates an ID number for each employee that is added to the record. The number increases each time automatically. This allows you to easily reference employees with other functions. Although VARCHAR allows you to trim the size based on input, you can set a limit for it so that the user can’t input strings that are too large. In the above example, both first name and last name are limited to 20 characters each. Note that the phone number entry is stored as VARCHAR so that symbols are handled correctly.
By entering NULL for the ID, the value will increase by 1 from the last entry, resulting in the next ID number. Make sure that each value you enter has single quotes (’) around it.
You can perform more advanced displays by adding filters to the search. For example, to return the table sorted by date of birth, you would type SELECT lastname, firstname, dateofbirth FROM employees ORDER BY dateofbirth Reverse the order of the results by adding DESC to the end of the command.