MySql基本操作

來源:互聯網
上載者:User

標籤:

  • 資料庫操作

建立資料庫

create database 資料庫名 character set utf8

刪除資料庫

drop database 資料庫名
  • 表操作

建立表:(auto_increment自增、unique唯一)

--建立新表 create table t_user( id bigint primary key auto_increment, username varchar(50) unique,  name varchar(20), password varchar(20), sex varchar(1) );--根據已有表建立新表create table tab_new like tab_old 

 

表本身操作

--表重新命名alter table 表名 rename 新表名--刪除表drop table 表名

表的其它操作

--添加主鍵 Alter table tabname add primary key(col)--刪除主鍵 Alter table tabname drop primary key(col)--建立索引create [unique] index idxname on tabname(col….)--刪除索引drop index idxname--建立視圖create view viewname as select statement--刪除視圖drop view viewname

 

 

 

表欄位增、刪、改

--添加alter table   table1 add id int not Null auto_increment primary key--修改一個欄位類型alter table 表名稱 modify 欄位名稱 欄位類型 [是否允許非空];--修改一個欄位類型連著欄位名alter table 表名稱 change 欄位原名稱 欄位新名稱 欄位類型 [是否允許非空]--刪除一個欄位alter table mytable drop 欄位名

 

 

  • 資料操作

1.插入資料

insert into students (name, sex, age) values("孫麗華", "女", 21);

 

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.