Article From:

These are the notes taken by the tutor and the teacher.


Create a table and view the structure
1 Advanced into a database. BREATE TABLE table name;
2 Input the command to build the table
CREATE TABLE The name of the table {
The 1 types of column names [constraint],
The 2 types of column names [constraint],
The 3 types of column names [constraint],
The 4 types of column names [constraint],
Column name 5 type [constraint]

For example, CREATE TABLE `t_student` {{
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
`email` varchar(40) DEFAULT NULL,
`age` int(11) DEFAULT NULL,

Notice that the last line has no comma. The general table name is prefixed with ‘t_’.
Delete the new syntax of the table: DROP TABLE IF EXISTS table name;

If the database is used in the built table
For example, use order to represent orders, and write table names to order.
orderIs the keyword in the SQL, indicating the intent of the sort.
Terms of settlement:
1 Avoid the use of keywords and change a word
2 If it’s a table name, someone is used to using t_ as a prefix
3 Use anti quotation marks (‘) to wrap up the `order`, and the columns in the table are also enclosed by an inverted quotation mark.

Two view the structure of the table

DESC Table name;

The following is the name of the table: t_student;


show create table Table name;

The following is the name of the table: t_student;


Various constraints of the table

  1.  Non empty constraint, NOT NULL, does not allow a column to be empty.
  2.  Set the default value of the column, DEFAULT
  3.  The only constraint, UNIAUE, is that the value is unique in the table.
  4.  The primary key constraint, the PRIMARY KEY. is non empty and unique. The unique identity of each line
  5.  The main key is self – growing, AUTO_ INCREMENT, starting from 1.

What is the primary key: unique identification, such as ID, human identity card, personal experience of learning MySQL
The design of the main key:

  1. But the field primary key, single column as the primary key, is recommended.

             Composite primary keys, using multiple columns as primary keys, are not recommended.

  1. Classification of main keys

    A Natural primary key: using a column with a business meaning as the primary key is not recommended.
    B Proxy key: use a column with no business meaning as the primary key.


Link of this Article: Some operations of the MySQL table

Leave a Reply

Your email address will not be published. Required fields are marked *