基礎 使用 mysql 命令

來源:互聯網
上載者:User

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++mysql 基礎操作<br />//主鍵549830479<br /> alter table tabelname add new_field_id int(5) unsigned default 0 not null auto_increment ,add primary key (new_field_id);<br />//增加一個新列549830479<br /> alter table t2 add d timestamp;<br />alter table infos add ex tinyint not null default '0';<br />//刪除列549830479<br /> alter table t2 drop column c;<br />//重新命名列549830479<br /> alter table t1 change a b integer;<br />//改變列的類型549830479<br /> alter table t1 change b b bigint not null;<br />alter table infos change list list tinyint not null default '0';<br />//重新命名表549830479<br /> alter table t1 rename t2;<br />加索引549830479<br /> mysql> alter table tablename change depno depno int(5) not null;<br />mysql> alter table tablename add index 索引名 (欄位名1[,欄位名2 …]);<br />mysql> alter table tablename add index emp_name (name);<br />加主關鍵字的索引549830479<br />mysql> alter table tablename add primary key(id);<br />加唯一限制條件的索引549830479<br /> mysql> alter table tablename add unique emp_name2(cardnumber);<br />刪除某個索引549830479<br /> mysql>alter table tablename drop index emp_name;<br />修改表:549830479<br />增加欄位:549830479<br /> mysql> ALTER TABLE table_name ADD field_name field_type;<br />修改原欄位名稱及類型:549830479<br /> mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;<br />刪除欄位:549830479<br /> mysql> ALTER TABLE table_name DROP field_name; </p><p>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++mysql 約束<br />--------添加主鍵約束(bookid作為主鍵)<br />alter table bookmessage<br />add constraint pk_bookid primary key(bookid)<br />--------添加唯一約束<br />alter table bookmessage<br />add constraint uq_bookid UNIQUE(bookid)<br />---------添加預設約束<br />alter table bookmessage<br />add constraint df_address DEFAUIT('地址不詳') for Address<br />--------添加檢出約束,要求年齡只能在15---40之間<br />alter table readermessage<br />add constraint CK_age CHECK(age BETWEEN 15 AND 40)<br />-------添加外鍵約束<br />alter table bookmessage<br />add constraint fk_bookid<br />foreign key(bookid)<外鍵> references readermessage<表>(readerid)<表中的主鍵><br />-------刪除約束<br />alter table 表名<br />drop constraint 約束名<br />+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br />

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.