MySql DDL语言(数据库和数据表的管理)
數(shù)據(jù)定義語(yǔ)言,負(fù)責(zé)數(shù)據(jù)庫(kù)和數(shù)據(jù)表的管理
⒈數(shù)據(jù)庫(kù)的管理
1.創(chuàng)建數(shù)據(jù)庫(kù)
1 create database if not exists DatabaseName; #if not exists可以省略2.修改數(shù)據(jù)庫(kù)
①重命名數(shù)據(jù)庫(kù)名稱(已經(jīng)廢棄,強(qiáng)制修改只能到數(shù)據(jù)庫(kù)指向的文件夾重命名后重啟服務(wù))
1 rename database oldDatabaseName to newDatabaseName;②修改數(shù)據(jù)庫(kù)的字符集
1 alter database DatabaseName character set utf8;3.刪除數(shù)據(jù)庫(kù)
1 drop database if exists DatabaseName; #if exists可以省略⒉數(shù)據(jù)表的管理
1.創(chuàng)建數(shù)據(jù)表
1 create table if not exists TableName( #if not exists可以省略 2 id int, 3 name varchar(50) 4 );2.修改數(shù)據(jù)表
①修改列名稱
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;⑤修改數(shù)據(jù)表名稱
1 alter table TableName rename to NewTableName;3.刪除數(shù)據(jù)表
1 drop table if exists TableName; #if exists可以省略4.復(fù)制數(shù)據(jù)表
①僅復(fù)制數(shù)據(jù)表結(jié)構(gòu)
1 create table NewTableName like TableName;②復(fù)制數(shù)據(jù)表結(jié)構(gòu)+數(shù)據(jù)表數(shù)據(jù)
1 create table NewTableName select * from TableName;③只復(fù)制部分?jǐn)?shù)據(jù)表數(shù)據(jù)
1 create table NewTableName select id from TableName where id between 10 and 15;④僅僅復(fù)制某些字段
1 create table NewTableName select id from TableName where 0;0代表恒不成立,可以1=2替代,1代表成立,若篩選條件不成立,則認(rèn)為沒(méi)有合適的數(shù)據(jù),則只復(fù)制選中的結(jié)構(gòu)
?
轉(zhuǎn)載于:https://www.cnblogs.com/fanqisoft/p/10697710.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的MySql DDL语言(数据库和数据表的管理)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: apache服务器性能诊断,Apache
- 下一篇: 思科查看服务器启动配置文件,启动配置检查