MySQL table operations

Source: Internet
Author: User

Storage Engine
    • The storage engine is a table type, and MySQL has different processing mechanisms depending on the table type
    • Table is equivalent to a file, a record in the table is equivalent to a row of the file, but a record in the table has a corresponding title, called the table field
    • Create a table

      Grammar:
      CREATE TABLE Table name (
      Field name 1 type [(width) constraint],
      Field Name 2 Type [(width) constraint],
      Field Name 3 Type [(width) constraint]
      );

      Attention:
      1. Field names cannot be the same in the same table
      2. Width and constraints are optional
      3. Field names and types are required
# Create Data folderMariaDB [(None)]>Create Database DB1 CharSet UTF8;# Toggle FolderMariaDB [(None)]>Use DB1;# Create a file tableMariaDB [DB1]>CREATE TABLE T1 ( - ID int, -Name varchar ( -), -Sex enum (' Male ',' Female '), -Ageint(3) -);#查看db1库下所有表名MariaDB [DB1]>Show tables; # view Table StructureMariaDB [DB1]>Desc T1;+-------+-----------------------+------+-----+---------+-------+|Field|Type|Null|Key|Default|Extra|+-------+-----------------------+------+-----+---------+-------+| ID    | int( One)|YES|     |Null|       ||Name|varchar -)|YES|     |Null|       ||Sex|Enum' Male ',' Female ')|YES|     |Null|       ||Age| int(3)|YES|     |Null|       |+-------+-----------------------+------+-----+---------+-------+# View Some fields in the tableMariaDB [DB1]>SelectID, Name,sex,age fromT1;EmptySet(0.00Sec# View all fields in a tableMariaDB [DB1]>Select*  fromT1;EmptySet(0.00Sec# Insert an entire row into the table fileMariaDB [DB1]>INSERT INTO T1 values -(1,' Egon ', -,' Male '), -(2,' Alex ',Bayi,' Female ') - ;MariaDB [DB1]>Select*  fromT1;+------+------+------+--------+| ID   |Name|Age|Sex|+------+------+------+--------+|    1 |Egon|    - |Male||    2 |Alex|   Bayi |Female|+------+------+------+--------+# Insert data into a table (a specific field)MariaDB [DB1]>INSERT INTO T1 (ID) values -(3), -(4);MariaDB [DB1]>Select*  fromT1;+------+------+------+--------+| ID   |Name|Age|Sex|+------+------+------+--------+|    1 |Egon|    - |Male||    2 |Alex|   Bayi |Female||    3 |Null|Null|Null||    4 |Null|Null|Null|+------+------+------+--------+

MySQL table operations

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.