常用的sql定义语言(DDL)
DDL(Data Definition Languages:数据库定义语言):这些语句定义了不同的数据库、表、视图、索引等数据库对象,还可以用来创建、删除、修改数据库和数据表的结构。
主要的语句关键字包括:CREATE、DROP、ALTER、RENAME、TURUNCATE等
库的管理
1.库的创建
-- 库的创建
create database book;
commit ;
create database if not exists book;
commit ;
-- 库的字符集的修改
alter database book character set gbk;
drop database if exists book;
表的创建
create table author(
id int,
name varchar(32),
birthday date
);
desc author;
-- 修改列名
alter table author change column birthday birday date;
-- 修改列的类型或者约束
alter table author modify column name varchar(64);
commit ;
-- 添加新列
alter table author add column age int;
commit ;
-- 删除列
alter table author drop column age;
commit ;
-- 修改表名
alter table author rename to book_au;
commit ;
-- 复制表的结构
create table author2 like author;
-- 复制表的结构和数据
create table author3 select * from author;
-- 复制表的结构和部分数据
create table author3 select * from author where name='1';
本文来自博客园,作者:King-DA,转载请注明原文链接:https://www.cnblogs.com/qingmuchuanqi48/articles/15968567.html

浙公网安备 33010602011771号