mysql sql enum資料類型插入,更新,刪除操作

來源:互聯網
上載者:User

mysql教程 sql enum資料類型插入,更新,刪除操作

enum列總有1個預設值。如果未指定預設值,對於包含null的列,預設值為null;否則,第1個枚舉值將被當作預設值。

  如果在enum列中插入了不正確的值,或者,如果使用ignore將值強制插入了enum列,會將其設定為保留的枚舉值0,對於字串情形,將顯示為空白字串。

  如果在set列中插入了不正確值,該值將被忽略。例如,如果列能包含值“a”、“b”和“c”,並賦值“a,x,b,y”,結果為“a,b”。

 

假設表: xxx 中有一欄位 folder 類型為enum('inbox','outbox','other') 

儲存

insert into `xxx` (`folder`) values ('inbox');
insert into `xxx` (`folder`) values ('outbox');
insert into `xxx` (`folder`) values ('other');

更新

update `xxx` set `folder` = 'inbox';
update `xxx` set `folder` = 'outbox';
update `xxx` set `folder` = 'other';

刪除

delete from `xxx` where `folder` = 'inbox';
delete from `xxx` where `folder` = 'outbox';
delete from `xxx` where `folder` = 'other';

enum類型定義好以後 操作跟 字串一樣.只是mysql處理的時候是用整形來操作..比操作字串快很多而已

看個執行個體

create table employee_person (
    id int unsigned not null primary key,
    address varchar(60),
    phone int,
    email varchar(60),
    birthday date,
    sex enum('m', 'f'),
    m_status enum('y','n'),
    s_name varchar(40),
    children int
);


insert into employee_person (id, address, phone, email, birthday, sex, m_status, s_name) values (1, '200, regina street', 7176666, 'net@hotmail.com', '1971-04-26', 'm', 'y', 'ane regina');
insert into employee_person (id, address, phone, email, birthday, sex, m_status, s_name, children) values (2, '1232 alberta road', 5553312, 'jo@hotmail.com', '1968-03-02', 'm', 'y', 'jane van', 3);

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.