MySQL表操作

來源:互聯網
上載者:User

標籤:建立   ase   編輯   alter   gnu   null   math   lis   rop   

使用編輯器編輯指令
edit
建立表
create table 表名(
欄位1,類型【寬度】約束條件)
==在同一張表中,欄位名是不能相同
==寬度和約束條件可選
==欄位名和類型是必須的
查看錶
show tables;
desc haha;查看錶結構
show create table haha;
show table status like ‘haha’ \G
修改表:
alter 修改表名稱 ,修改欄位名稱 修改欄位資料類型 修改欄位的修飾符
insert 插入資料
delete 刪除資料
update 更新資料
修改表名稱
rename table haha to xixi;
alter table hh rename xixi;
添加新欄位
alter table t1 add math int(10);
alter table t1 add (chinese int(10)),english int(10));
修改欄位資料庫類型,修飾符 alter只能改資料庫類型不能改名
alter table t1 modify chinese int(5) not null;
修改名稱,資料類型,修飾符
alter table t1 change chinese china int(6);
first after
alter table t1 change english en int(6) after id;
alter table t1 modify en int(6) first;
刪除欄位
alter table t1 drop en;
插入資料(添加記錄)
字串必須引號引起來
mysql> insert into t1(id,name,math,china) values(1,"wing",80,90);
mysql> insert into t1(id,name,math,china) values(2,"king",70,100),(3,"tom",50,70);
mysql> insert into t1 values(4,"xiaosan",50,100);
mysql> insert into t1(id,math) values(5,70);
mysql> insert into t1 set id=6,math=65;
更新記錄
mysql> update t1 set name="lili" where id=5;
刪除記錄
mysql> delete from t1 where id=6;
mysql> delete from t1; //刪除所有記錄
表複製:key不會被複製: 主鍵、外鍵和索引
複製一張表
mysql> create table t10(select * from t3);
mysql> create table t10(select id,name from t3);

複製表結構
mysql> create table t4(select * from t3 where 5=4);
mysql> create table t4(select id,name from t3 where 5=4);

複製記錄
mysql> insert into t3 select * from t10 where id=9;

刪除表
mysql> drop table t1;

刪除庫
mysql> drop database gnu;

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.