MySQL --- 11. Database table operations

11.1 to building a database default character set latin1

Since we set up the database and for the special character set and the client (as compiled binary installation, the default character set is latin1)

mysql> create database oldboy;
Query OK, 1 row affected (0.11 sec)
mysql> show create database oldboy;
+----------+-------------------------------------------------------------------+
| Database | Create Database |
+----------+-------------------------------------------------------------------+
| oldboy | CREATE DATABASE `oldboy` /*!40100 DEFAULT CHARACTER SET latin1 */ |
+----------+-------------------------------------------------------------------+
1 row in set (0.00 sec)​

11.2 build table and view the structure of the table

1, the basic construction of the table command syntax:

create table <table_name> {
<字段名 1><类型 1>
........
<字段名 n><类型 n>;
提示:其中 create table 是关键字,不能更改,但是大小可以变化​

2, construction of the table statement
following statement is an example of the construction of artificial writing table design, table student

mysql> use oldboy
Database changed
mysql> create table student(
 -> id int(4) not null,
 -> name char(20) not null,
 -> age tinyint(2) not null default '0',
-> dept varchar(16) default null
->);
mysql> show tables
+------------------+
| Tables_in_oldboy |
+------------------+
| student |
+------------------+
1 row in set (0.00 sec)​

View table structure has been built

mysql> show create table student\G;
*************************** 1. row ***************************
 Table: student
Create Table: CREATE TABLE `student` (
 `id` int(4) NOT NULL,
 `name` char(20) NOT NULL,
 `age` tinyint(2) NOT NULL DEFAULT '0',
 `dept` varchar(16) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.07 sec)
ERROR:
No query specified​

View table structure

mysql> describe student;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(4) | NO | | NULL | |
| name | char(20) | NO | | NULL | |
| age | tinyint(2) | NO | | 0 | |
| dept | varchar(16) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.13 sec)​

Character 11.3 mysql table type
11.3.1 numeric type

Date and time types 11.3.2

11.3.3 string type

11.3.4 About Character Type Summary

Guess you like

Origin www.cnblogs.com/shiyw/p/12382370.html