zoukankan      html  css  js  c++  java
  • MySql DDL语言(数据库和数据表的管理)

      数据定义语言,负责数据库和数据表的管理

    ⒈数据库的管理

      1.创建数据库   

    1 create database if not exists DatabaseName;    #if not exists可以省略

      2.修改数据库

        ①重命名数据库名称(已经废弃,强制修改只能到数据库指向的文件夹重命名后重启服务)

    1 rename database oldDatabaseName to newDatabaseName;

        ②修改数据库的字符集

    1 alter database DatabaseName character set utf8;

      3.删除数据库

    1 drop database if exists DatabaseName;    #if exists可以省略

    ⒉数据表的管理

      1.创建数据表

    1 create table if not exists TableName(    #if not exists可以省略
    2     id int,
    3     name varchar(50)
    4     );

      2.修改数据表

        ①修改列名称

    1 alter table TableName change column OldColumnName NewColumnName NewColumnType;

        ②修改列类型或约束

    1 alter table TableName modify column ColumnName NewColumnType;

        ③添加新列

    1 alter table TableName add column AddColumnName AddColumnType;

        ④删除列

    1 alter table TableName drop column ColumnName;

        ⑤修改数据表名称

    1 alter table TableName rename to NewTableName;

      3.删除数据表

    1 drop table if exists TableName;    #if exists可以省略

      4.复制数据表

        ①仅复制数据表结构 

    1 create table NewTableName like TableName;

        ②复制数据表结构+数据表数据

    1 create table NewTableName select * from TableName;

        ③只复制部分数据表数据

    1 create table NewTableName select id from TableName where id between 10 and 15;

        ④仅仅复制某些字段

    1 create table NewTableName select id from TableName where 0;

          0代表恒不成立,可以1=2替代,1代表成立,若筛选条件不成立,则认为没有合适的数据,则只复制选中的结构

  • 相关阅读:
    网站安全策略
    防止表单重复提交的几种策略
    Laravel5中防止XSS跨站攻击的方法
    PHP + ORACLE 远程连接数据库环境配置
    iview table表格内容为数组或者对象的子元素时问题讨论
    jquery中 $(xxx).each() 和 $.each()的区别,以及enter键一键登录
    vue.js 强行赋值、刷新数组或者对象 方法之 $.set()
    vue 组件,以及组件的复用
    vue 和 jquery混合使用
    JS清除空格之trim()方法
  • 原文地址:https://www.cnblogs.com/fanqisoft/p/10697710.html
Copyright © 2011-2022 走看看