mysql基本操作

來源:互聯網
上載者:User

標籤:

1.建立資料庫

create database test ;2. 建立表create table student (id int , name char(8) , sex char(4));—建立了一個student表,有id name sex 三個欄位3. 查看資料表欄位select columns from student ; show create table student ;describe student ;use information_schemaselect * from columns where table_name=‘表名‘;以上方法都可以。4. 插入資料insert [into] 表名 [(列名1, 列名2, 列名3, ...)] values (值1, 值2, 值3, …);[] 內的資料可以省略insert student values(1,’luyg’,’girl’);插入指定資料insert student (id,name) values(10,’kobe’);5. 更新資料update 表名稱 set 列名稱=新值 where 更新條件;6. 刪除資料delete from 表名稱 where 刪除條件;delete from test where id = 1 ; 7.修改表結構基本形式: alter table 表名 add 列名 列資料類型 [after 插入位置];樣本:在表的最後追加列 address: alter table students add address char(60);在名為 age 的列後插入列 birthday: alter table students add birthday date after age;8. 修改列基本形式: alter table 表名 change 列名稱 列新名稱 新資料類型;樣本:將表 tel 列改名為 telphone: alter table students change tel telphone char(13) default "-";將 name 列的資料類型改為 char(16): alter table students change name name char(16) not null;9. 刪除列基本形式: alter table 表名 drop 列名稱;alter table test drop name10.重新命名表基本形式: alter table 表名 rename 新表名;11.刪除表基本形式: drop database 資料庫名;

 

mysql基本操作

聯繫我們

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