zoukankan      html  css  js  c++  java
  • MySQL 表的命令

    1、查看表的结构:

      desc 表名;
      show columns from 表名;
      describe 表名;
      show create table 表名;

     

    2、修改表名

     

      rename table 原表名 to 新表名;

      例如:在表MyClass名字更改为YouClass
           mysql> rename table MyClass to YouClass;

      当你执行 RENAME 时,你不能有任何锁定的表或活动的事务。你同样也必须有对原初表的 ALTER 和 DROP 权限,以及对新表的 CREATE 和 INSERT 权限。

      如果在多表更名中,MySQL 遭遇到任何错误,它将对所有被更名的表进行倒退更名,将每件事物退回到最初状态。

      RENAME TABLE 在 MySQL 3.23.23 中被加入。

     

    3、创建数据表

      命令:create table <表名> ( <字段名1> <类型1> [,..<字段名n> <类型n>]);

      例如,建立一个名为MyClass的表,
    字段名 数字类型 数据宽度 是否为空 是否主键 自动增加 默认值
    id int 4 primary key auto_increment  
    name char 20      
    sex int 4     0
    degree double 16      

      mysql> create table MyClass(
           > id int(4) not null primary key auto_increment,
         > name char(20) not null,
           > sex int(4) not null default '0',
           > degree double(16,2));

    4、删除数据表

      命令:drop table <表名>

      例如:删除表名为 MyClass 的表
           mysql> drop table MyClass;

      DROP TABLE用于取消一个或多个表。您必须有每个表的DROP权限。所有的表数据和表定义会被取消,所以使用本语句要小心!

      注意:对于一个带分区的表,DROP TABLE会永久性地取消表定义,取消各分区,并取消储存在这些分区中的所有数据。DROP TABLE还会取消与被取消的表有关联的分区定义(.par)文件。

      对与不存在的表,使用IF EXISTS用于防止错误发生。当使用IF EXISTS时,对于每个不存在的表,会生成一个NOTE。

      RESTRICT和CASCADE可以使分区更容易。目前,RESTRICT和CASCADE不起作用。
  • 相关阅读:
    关于java中的继承
    jdk?jre?
    spring AOP的两种配置
    ng-repeat如何限制循环次数
    AngularJS filter:search 是如何匹配的 ng-repeat filter:search ,filter:{$:search},只取repeat的item的value 不含label
    Anjular的ng-repeat
    SpringBoot扫描不到类,注入失败A component required a bean of type 'XXService' that could...
    React路由安装使用和多种方式传参
    Vue详细介绍模板语法和过滤器的使用!
    Vue定义组件和生命周期函数及实例演示!
  • 原文地址:https://www.cnblogs.com/linguoguo/p/4323261.html
Copyright © 2011-2022 走看看