O'Reilly logo

MySQL 8 Cookbook by Karthik Appigatla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

The table contains the column definition:

mysql> CREATE TABLE IF NOT EXISTS `company`.`customers` (`id` int unsigned AUTO_INCREMENT PRIMARY KEY,`first_name` varchar(20),`last_name` varchar(20),`country` varchar(20)) ENGINE=InnoDB;

The options are explained as follows:

  • Dot notation: Tables can be referenced using database name dot table name (database.table). If you are connected to the database, you can simply use customers instead of company.customers.
  • IF NOT EXISTS: If a table with the same name exists and you specify this clause, MySQL simply throws a warning that the table already exists. Otherwise, MySQL will throw an error.
  • id: It is declared as an integer since it contains only integers. Along with that, there are ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required