mysql常用語句

來源:互聯網
上載者:User

修改表:

添加欄位:alter table yyh_yp_managerrob add catid  smallint(5)
 , add typeid  smallint(5)
, add areaid  smallint(5)
, add title char(150)
, add style char(5)
, add thumb char(100)
, add keywords char(40)
, add description char(255)
, add posids tinyint(1)
, add url char(100)
, add listorder tinyint(3)
, add status tinyint(2)
, add userid mediumint(8)
, add username char(20)
, add inputtime int(10)
, add updatetime int(10)
, add searchid mediumint(8)
, add islink tinyint(1)
, add prefix char(20);

複製表結構:create table newtable (select * from oldtable)

還原資料庫:

先刪除掉原有的資料庫:drop database 資料庫名稱
然後建立資料庫:creat database 資料庫名稱
然後:use 資料庫名稱
然後:source .sql檔案的路徑

補充:

MySQL添加欄位的方法並不複雜,下面將為您詳細介紹MySQL添加欄位和修改欄位等操作的實現方法,希望對您學習MySQL添加欄位方面會有所協助。

1.登入資料庫
>mysql -u root -p 資料庫名稱

2.查詢所有資料表
>show tables;

3.查詢表的欄位資訊
>desc 表名稱;

4.1添加表欄位

alter table table1 add transactor varchar(10) not Null;

alter table   table1 add id int unsigned not Null auto_increment primary key

4.2.修改某個表的欄位類型及指定為空白或非空
>alter table 表名稱 change 欄位名稱 欄位名稱 欄位類型 [是否允許非空];
>alter table 表名稱 modify 欄位名稱 欄位類型 [是否允許非空];

>alter table 表名稱 modify 欄位名稱 欄位類型 [是否允許非空];

4.3.修改某個表的欄位名稱及指定為空白或非空
>alter table 表名稱 change 欄位原名稱 欄位新名稱 欄位類型 [是否允許非空

4.4如果要刪除某一欄位,可用命令:ALTER TABLE mytable DROP 欄位 名;

聯繫我們

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