TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

MySQL

Create a Table in MySQL Database

Overview

In this tutorial, we will learn how to create a table in MySQL database. A database is like container for database objects like tables, views, etc. We need to create a database before creating database tables. Steps to create a database in MySQL server:

https://www.testingdocs.com/create-a-new-mysql-database/

Example

Let’s look at an example. We use the CREATE TABLE SQL statement to create a table with the given name in the MySQL database. We can specify the default database using the USE statement.

MySQL database tables are created using the default InnoDB storage engine. We can find the default storage option in the my.ini configuration file.

We can specify the database name in the SQL statement. The sample table has two columns with different data types. The first column is of integer and the second column is of string of characters.

 

CREATE TABLE IF NOT EXISTS testdb.supplier (
supplier_id int PRIMARY KEY,
supplier_name VARCHAR(40) NOT NULL);

 

Alternatively, we can connect to the database using the USE statement. For example, to connect to the testdb, we can use the following statement:

mysql> USE testdb

Create Table in MySQL database Win10

Statements

mysql> USE testdb;
Database changed
mysql> CREATE TABLE IF NOT EXISTS supplier (
-> supplier_id int PRIMARY KEY,
-> supplier_name VARCHAR(40) NOT NULL);
Query OK, 0 rows affected (0.67 sec)

mysql> SHOW TABLES;
+——————+
| Tables_in_testdb |
+——————+
| supplier |
+——————+
1 row in set (0.32 sec)

mysql>

Common Errors

Duplicate Table: An error occurs if the table already exists in the MySQL database.

No default database : Error occurs if there is no default database

No Database : Error occurs if the database does not exist.

Syntax Errors : The SQL statement has syntax errors.

—

MySQL Tutorials

MySQL Tutorials on this website:

https://www.testingdocs.com/mysql-tutorials-for-beginners/

For more information on MySQL Database:

https://www.mysql.com/

Related Posts

DataGrip Desktop Shortcut

MySQL /

Launch DataGrip on Windows

DataGrip Download

MySQL /

Install DataGrip IDE on Windows 11

MySQL Workbench Windows 11

MySQL /

New MySQL Connection in Workbench

MySQL Command-line Client

MySQL /

Command-Line MySQL Client

Start MySQL Client

MySQL /

Start MySQL Client on Windows 11

‹ Basic MySQL Commands› MySQL GROUP BY Clause

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version