mySQL筆記(1)

來源:互聯網
上載者:User

標籤:

1.show databases;     顯示所有資料庫

2.create database 資料庫名  [其他選項];     建立資料庫

    例:create database example_db  character set gbk;  建立了一個名為example_db的資料庫,並將資料庫字元編碼指定為gbk,便於在命令提示字元下顯示中文。

3.use 資料庫名;  選擇要用的資料庫

4.show tables;     顯示已選擇的資料庫中的所有表

5.create table 表名(列名  資料類型,........);    建立表

    例:create table students(

                  id   int    not null    primary key,

                 name  char(8)  not null,

                 password  varchar(20) 

);              

6.alter table 表名  add  要插入的列名稱   資料格式  [after 插入位置];;            在建好的表中插入一列

     例:alter table students add tel varchar(13)  after password;

7.alter table 表名  drop column  要刪除的列名稱;              在建好的表中刪除一列

     例:alter table students drop column tel;

8.insert 【into】 表名(列名1,列名2,......)values(列值1,列值2,......);      在表中插入資料

    例:insert into students(id,name) values(01,‘李明‘);

           或 insert students values(01,‘李明‘,‘qwe123‘);

9.select * from 表名 where 查詢條件;       查詢滿足條件的表中的所有資訊

   select 列名 from 表名 where 查詢條件;       查詢滿足條件的所有列資訊

    例:select id,name  from students;

10.update 表名 set 列名=新值 where  更新條件;  修改表中的資料

    例:update students set id=id+1 where name=‘李明‘;

11.delete from 表名  where 刪除條件;

    例:delete  from  students  where name=‘李明‘;

12.drop table 表名;     刪除整張表

13.drop database 資料庫名;     刪除整個資料庫

14.alter table 表名 change 列名 列新名稱 新資料類型;     修改列

    例:alter table students change password password char(10) not null;

15.alter table 表名 rename 新表名;       重新命名表

 

註:參考http://www.cnblogs.com/mr-wid/archive/2013/05/09/3068229.html

 

mySQL筆記(1)

聯繫我們

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