数据库基本操作一:DDL

  • 对数据库常用操作

  • 对表结构常用操作

  • 修改表结构

1. 对数据库常用操作

  • 查看所有的数据库

show databases;
  • 创建数据库

create database if not exists mydatabase1;
  • 切换需要执行的数据库

use mydatabase1;
  • 删除数据库

drop database if exists mydatabase1;

2.对表结构的常用操作

  • 创建表

create table if not exists student(
    stuid int,
    name varchar(20),
    gender varchar(20),
    birth date,
    age int,
    score double
);

注意:创建表后要加分号,最后一列数据后不加逗号,执行前需要切换到要执行的数据库。

  • 其他操作

    • 查看当前所有的表

      show tables;
    • 查看某个表的创建语句

      show create table student;
    • 查看表结构

      desc student;
    • 删除表

      drop table if exists student;
  • 修改表结构

    • 添加列

      alter table student add `address` varchar(20);
    • 修改列名和类型

      alter table student change `address` stuaddress varchar(30);
    • 删除列

      alter table student drop `stuaddress`;
    • 修改表名

      rename table student to studentinformation;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值