Create a datasheet use
Command: CREATE table < table name > (< Field name 1> < type 1> [,.. < Field name N> < type n>];
Syntax: CREATE [temporary] TABLE [IF not EXISTS] tbl_name [(create_definition,...)] [Table_options] [Select_statement]
Cases
The code is as follows |
Copy Code |
Mysql> CREATE TABLE MyClass ( > ID int (4) NOT null primary key auto_increment, > name char (NOT NULL), > Sex int (4) NOT null default ' 0 ', > Degree double (16,2)); |
Detailed parameters
Temporary: This keyword indicates that the newly created table with MySQL CREATE TABLE is a temporary table that will automatically disappear after the current session ends. Temporary tables are mainly used in stored procedures, and for MySQL, which does not currently support stored procedures, this keyword is generally not available.
IF not EXISTS: In fact, add a judgment before the table is being built to perform the CREATE TABLE operation only if the table does not currently exist. Use this option to avoid errors where the table already exists and cannot be created again.
Tbl_name: The table name of the table you want to create. The table name must conform to the rules for identifiers. The usual practice is to use only letters, numbers, and underscores in the table name. For example, titles, Our_sales, My_user1 and so on should be regarded as the table name of the comparison specification.
Create_definition: This is the key part of the MySQL CREATE TABLE statement. The properties of each column in the table are specifically defined in this section.
Delete Table command : Drop table < table name >
mysql> drop table MyClass;
DROP table is used to cancel one or more tables. You must have drop permissions for each table. All table data and table definitions will be canceled, so be careful with this statement!
And then share some of the table-related commands.
Get table structure
Command: DESC table name, or Show columns from table name
The code is as follows |
Copy Code |
mysql> desc MyClass; Mysql> show columns from MyClass; |
Insert Record
Command: INSERT into < table name > [< field name 1>[,.. < field name n >]] VALUES (value 1) [, (value N)]
For example: Insert two records into table MyClass, two records indicate that: Tom with a number 1 is 96.45, and the number 2 for Joan is 82.99, and the number 3 for Wang is 96.5.
mysql> INSERT INTO MyClass values (1, ' Tom ', 96.45), (2, ' Joan ', 82.99), (2, ' Wang ', 96.59);
Note: INSERT into only one record in the table at a time.