SQL語言的學習 DDL 庫和表的管理

2022-09-09 13:33:23 字數 1416 閱讀 5742

1、庫的建立

/*語法:

create database [if not exists]庫名;

*/create database if not exists books ;

2、庫的修改

rename database books to 新庫名;

alter database books character set gbk;

3、庫的刪除

drop database if exists books;

1.表的建立 ★

/*語法:

create table 表名(

列名 列的型別【(長度) 約束】,

列名 列的型別【(長度) 約束】,

列名 列的型別【(長度) 約束】,

...列名 列的型別【(長度) 約束】)*/

create table book(

id int,#編號

bname varchar(20),#圖書名

price double,#**

authorid int,#作者編號

publishdate datetime#出版日期

desc book;

)desc author;

2.表的修改

/*語法

alter table 表名 add|drop|modify|change column 列名 【列型別 約束】;

alter table book change column publishdate pubdate datetime;

alter table book_author drop column annual;

alter table author rename to book_author;

desc book;

3.表的刪除

drop table if exists book_author;

show tables;

drop database if exists 舊庫名;

create database 新庫名;

drop table if exists 舊表名;

create table 表名();

4.表的複製

insert into author values

(1,'村上春樹','日本'),

(2,'莫言','中國'),

(3,'馮唐','中國'),

(4,'金庸','中國');

select * from author;

select * from copy2;

create table copy like author;

create table copy4

select id,au_name

from author

where 0;

SQL(5) DDL語言 庫和表的建立,修改和刪除

第一部分的內容 sql 2 dql語言 條件查詢 排序查詢 常見函式 分組查詢 連線查詢 sql 3 dql語言 子查詢 分頁查詢 聯合查詢 sql 4 dml語言 增刪改 資料定義語言 庫和表的管理 一 庫的管理 建立 修改 刪除 二 表的管理 建立 修改 刪除 建立 create 修改 alte...

資料定義語言DDL 庫和表的管理

建立 create 修改 alter 刪除 drop語法 create database if notexists 庫名 create database ifnot exists booksrename database books to 新庫名 alter database books chara...

MySQL之DDL庫和表的管理

資料定義語言 針對的是表的結構 庫和表的管理 一 庫的管理 建立 修改 刪除 二 表的管理 建立 修改 刪除 建立 create 修改 alter 刪除 drop 語法 create database if not exists 庫名 character set 字符集名 案例 建立庫books 如...