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:
- Field names cannot be the same in the same table
- Width and constraints are optional
- 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