zoukankan      html  css  js  c++  java
  • MySQL---11.数据库表操作

    11.1 以默认字符集 latin1 建库

    由于我们并为特别设置数据库及客户端字符集(因为编译是二进制安装,默认是 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 建立表并查看表的结构

    1、建表的基本命令语法:

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

    2、 建表语句
    下面是人工写法设计的建表语句例子,表名 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)​
    

    查看已建表的结构

    mysql> show create table studentG;
    *************************** 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​
    

    查看表结构

    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)​
    

    11.3 mysql 表的字符类型
    11.3.1 数字类型

    11.3.2 日期和时间类型

    11.3.3 字符串类型

    11.3.4 关于字符类型总结

  • 相关阅读:
    Java I/O基础
    Python基础篇(九)
    Python基础篇(八)
    thinkphp5中Indirect modification of overloaded element of XXX has no effect的解决办法
    关于json_encode转义斜杠的问题
    [thinkexceptionErrorException] glob() has been disabled for security reasons
    CentOS7 安装svn
    -bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory
    php在线编辑本地文件方法共享
    python一些不错的东西
  • 原文地址:https://www.cnblogs.com/treeskyer/p/14017124.html
Copyright © 2011-2022 走看看