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

2021-10-24 13:17:31 字數 1867 閱讀 8246

建立: create

修改: alter

刪除: drop

語法:

create

database[if

notexists

]庫名;

create

database

ifnot

exists books

rename database books to 新庫名;
alter

database books character

set gbk

drop

database

ifexists books;

語法:

create table 表名(

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

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

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

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

)

create

table book(

id int

,#編號

bname varchar(20

),#圖書名

price double

,#**

authorid int

,#作者編號

publishdate datetime

#出版日期

);

語法

alter

table 表名 add

|drop

|modify

|change column 列名 【列型別 約束】;

alter

table book change column publishdate pubdate datetime

;

alter

table book modify

column pubdate timestamp

;

alter

table author add

column annual double

;

alter

table book_author drop

column annual;

alter

table author rename

to book_author;

drop

table

ifexists book_author;

create

table copy like author;

create

table copy2

select

*from author;

create

table copy3

select id,au_name

from author

where nation=

'中國'

;

create

table copy4

select id,au_name

from author

where

0;

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

create database if not exists 庫名 案例案例一 建立庫books create database ifnot exists books ifnot exists 容錯性處理隨著mysql版本的公升級,庫名不能修改 更改資料庫字符集 alter database book...

DDL(管理資料庫和表)

create database 資料庫名 例 mysql create database runoob 也可以直接使用mysqladmin來建立資料庫 mysqladmin u root p create 資料庫名show databases 注意結尾的sdrop database 資料庫名 也可以...

DDL 資料庫定義語言

建表 id name age drop talbe if esists student create table student id int primary keyauto increment,name varchar 20 not null,age int not null default 18...