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

    MySQL

    MySQL CREATE TABLE Statement

    Overview

    In this tutorial, we will learn about MySQL CREATE TABLE Statement. After the database structure
    is designed and the database has been created, we can add the individual tables to the database.

    CREATE DATABASE statement can be found at:

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

    Syntax

    The general statement syntax is shown below:

    CREATE TABLE <table name> (
    <column name> <column type> [<column options>],
    [<column name> <column type> [<column options>],….,]
    [,<primary key definition>]
    );

    Example

    In this example, we will create CountryLanguage database table in the world MySQL database.

    CREATE TABLE CountryLanguage (
    CountryCode CHAR(3) NOT NULL,
    Language CHAR(30) NOT NULL,
    IsOfficial ENUM(‘True’, False’) NOT NULL DEFAULT ‘FALSE’,
    Percentage FLOAT(3,1) NOT NULL,
    PRIMARY KEY(CountryCode, Language)
    );

     

    Description

    Description of the CREATE TABLE statement is as follows:

    We create a table called CountryLanguage. ( is the beginning of the table structure definition that ends  with the ).

    CountryCode: Column is assigned the data type of CHAR and maximum length of 3 characters that cannot contain NULL . The comma at the end of the line indicates that you will continue defining columns, or set a primary key.

    Language:Column of the data type CHAR and a length of 30, also with no NULLs.

    IsOffical: Column is assigned the data type of ENUM( with the value of ‘True’ or’ False’), and the addition of NOT NULL means each row must be true or false, not NULL. If the field is not provided it will be set to ‘False’ by the phrase DEFAULT ‘False’.

    Percentage: Column with the data type of FLOAT and values assigned at 3 total digits of decimal and 1 digit to the right, cannot have NULL values.

    PRIMARY KEY:  Defines the type of key and to what columns it applies, in this case a combination of both CountryCode and Language columns to define a unique identifier for each row.

     

    ) is the closing of the table structure definition.

    The semi-colon ; means execute this statement (using the MySQL command line client) and create the table CountryLanguage database table.

    —

    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

    Stellar Converter for Database Tool

    MySQL /

    Stellar Converter for Database

    Stellar MySQL Log Analyzer

    MySQL /

    Stellar Log Analyzer for MySQL

    Stellar Repair for MySQL

    MySQL /

    Stellar Repair for MySQL

    MySQL /

    How to secure your SQL Database: Tips and Tricks

    Stellar Converter for Database

    MySQL /

    Database Converter Tools

    ‹ MySQL Constraints› MySQL SHOW CREATE TABLE Statement

    Recent Posts

    • ChatGPT Plans Free and PlusChatGPT Subscription Plans
    • Stellar Converter for Database ToolStellar Converter for Database
    • Stellar MySQL Log AnalyzerStellar Log Analyzer for MySQL
    • Stellar Repair for MySQLStellar Repair for MySQL
    • ChatGPT IntroductionChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI FeaturesChatGPT4 Conversational AI Features
    • Trends in Software EngineeringShaping the Future of Development: Exploring Key Trends in Software Engineering
    • Java PerformanceImproving Java Performance with Multithreading
    • QDrant Vector DatabaseOpen-source Vector Databases
    • Difference between PHP and JavaScript?
    • Bing AI Browser Web ContentBing Conversation Styles
    • ChatGPT PreviewChatGPT Introduction
    • Open Source AI Frameworks TensorFlowOpen Source AI Frameworks
    • Artificial Intelligence Tools

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com