mysql 笔记三
MySQL-3
查看表
1. describe 查看表的基本定義 describe | desc table_name2. show create table 查看表的詳細(xì)定義 show create table table_name;3. show tables 查看所有表的表名修改表的結(jié)構(gòu)
添加字段(ADD)
alter table table_name add [colmun] column_definition [first | after col_name] first 可選參數(shù),將新添加的字段設(shè)置為表的第一個(gè)字段。 after 可選參數(shù),將新添加的字段添加到指定的列col_name 后面。alter table text4 add sex enum('nan','nv') after id;修改表名(rename)
alter table table_name rename [to] new_table_name alter table test2 rename te;修改字段名(change)
alter table table_name change column_name new_column_name column_definition [FIRST | AFTER col_name]¥ column_definition: 字段列的定義,包括數(shù)據(jù)類(lèi)型和約束條件。¥ FIRST : 可選參數(shù),將字段設(shè)置為表的第一個(gè)字段。¥ AFTER : 可選參數(shù),將字段修改到指定的列 col_name 后面。- EX: alter table te change name 名字 varchar(20);修改字段類(lèi)型(modify)
alter table table_name modify column_name column_definition [FIRST | AFTER col_name]- ex - 通常是編碼格式問(wèn)題ERROR 1291 (HY000): Column '性別' has duplicated value '?' in ENUMtry1: ALTER TABLE `te` CHANGE `性別` `性別` VARCHAR(36) CHARACTER SET utf8 NOT NULL;try2: alter table te DEFAULT CHARACTER SET utf8;還是不成功?**EX:** alter table te modify 性別 enum('男','女') first;刪除字段(drop)
alter table table_name drop column_name**EX:** alter table te drop 性別; ?修改表的默認(rèn)儲(chǔ)存引擎(engine)和字符集(charset)
alter table table_name [default] engine = {myisam | innodb} charset = [gbk|utf8|...]EX: alter table te engine=myisam, charset=gbk;刪除表
drop table [if exists] table_name1,table_name2...;EX: drop table te; ?復(fù)制表
create [temporary] table [if not exists] table_name [like old_table_name] |[as (select_statement)];關(guān)于空值(NULL)的說(shuō)明
空值通常用于表示未知、不可用或?qū)⒃谝院筇砑拥臄?shù)據(jù),切不可將它與數(shù)字0或字符串類(lèi)型的空字符串混為一談。關(guān)于列的標(biāo)志(identity)屬性
任何表都可以創(chuàng)建一個(gè)包含系統(tǒng)所生成序號(hào)值得標(biāo)志列。該序號(hào)值唯一標(biāo)識(shí)表中的一列,且可以作為鍵值。關(guān)于列類(lèi)型的隱含改變
在MySQL中,系統(tǒng)會(huì)隱含的改變?cè)赾reate table 語(yǔ)句或 alter table 語(yǔ)句中所?定的列類(lèi)型。
長(zhǎng)度小于4的varchar類(lèi)型會(huì)被改變?yōu)閏har類(lèi)型
轉(zhuǎn)載于:https://www.cnblogs.com/duoban/p/11536435.html
總結(jié)
- 上一篇: IE9 Preview 4的CSS3支持
- 下一篇: 如何利用System.Net.Mail类