MySQL Keywords
In this article, we go over various MySQL keywords.
This is going to be ongoing list that will be constantly updated.
NOT NULL
The keywords NOT NULL can be declared in the definition of a MySQL column. Declaring a column NOT NULL means that the data entered into the rows of this column cannot be NULL, meaning there has to be a value entered into it. The data will not be entered into the MySQL table unless there is content being entered it. In other words, an actual value must be entered into the rows of this column. It cannot be a NULL value entered in.
Usually, you want a column to be NOT NULL. This is because you don't want empty strings in the table.
However, in certain cases, you may accept empty strings from uses. In this case, you would simply not add the NOT NULL line to the
column definition.
If you use a service such as phpMyAdmin, without changing the settings, it will create all columns to be NOT NULL by default.
UNIQUE
The keyword UNIQUE can be declared in the definition of a MySQL column. Declaring a colum UNIQUE means that no values entered into the rows of this column can be duplicated. Therefore, each value must be unique.
You would declare column unique when no values in the row can be duplicated. Examples include things such as
social security numbers, email addresses, possibly cell phone numbers. Since each individual is separate, they cannot have the same
social security number, email address, etc. Therefore, in these situations, it is appropriate and rightful to make the column unique.
PRIMARY KEY
The keywords PRIMARY KEY can be declared in the definition of a MySQL column. No, one or multiple columns can be declared to be a PRIMARY KEY. Declaring a column a PRIMARY KEY means forces the column be NOT NULL and UNIQUE. This means that each row in a column must contain a value (it cannot be an empty string) and each row must have a unique value.
Usually, by convention, a MySQL table should have an ID column. Usually this column is declared to be a primary key that
counts from 1 to how many rows there are. Usually, autoincrement goes in hand with this, so that each row is sequential. However,
for certain tables, it may not be this way.
Related Resources
How to Connect to a MySQL Database Using PHP
How to Create a MySQL Table Using PHP
How to Select a Table from a MySQL Database
How to Check if a MySQL Table Exists Using PHP
How to Delete a MySQL Table Using PHP
How to Rename a MySQL Table Using PHP
How to Add a Column to a MySQL Table Using PHP
How to Add a Primary Key to a Column of a MySQL Table Using PHP
How to Make a Column of a MySQL Table Unique Using PHP
How to Rename a Column of a MySQL Table Using PHP
How to Delete a Column of a MySQL Table Using PHP
How to Set the Default Value of a Column of a MySQL Table Using PHP
How to Drop the Default Value of a Column Of a MySQL Table Using PHP
How to Modify the Defintion or Data Type of a Column of a MySQL Table Using PHP
How to Insert Data into a MySQL Table Using PHP
How to Delete a Row of a MySQL Table Using PHP
How to Insert Data Into a Table of a MySQL Database From an HTML Form Using PHP
How to Update a Value in a MySQL Table Using PHP
How to Get the Sum of All Rows of a Column of a MySQL Table Using PHP
How to Get the Average of All Rows of a Column of a MySQL Table Using PHP
How to Get the Minimum Value of a Column of a MySQL Table Using PHP
How to Get the Maximum Value of a Column of a MySQL Table Using PHP
How to View User Privileges of a MySQL database Using PHP
How to Display a MySQL Table of a Database using PHP
How to Find the Number of Rows in a MySQL Table Using PHP
How to Sort a Field of a MySQL Table in Ascending Order in PHP
How to Select Specific Columns from a MySQL Table Using PHP
How to Display Certain Fields of a Table in MySQL Using PHP
How to Select a Specific Row of a MySQL Table Using PHP
How to Insert Images into a MySQL Database Using PHP
How to Insert Videos into a MySQL Database Using PHP
How to Insert Files into a MySQL Database Using PHP