mysql資料庫常用語句

來源:互聯網
上載者:User

標籤:

關於mysql資料庫常用命令的整理:

 

一:對於資料庫的操作

show databases;顯示目前使用者下所有的資料庫名稱

use database_name;進入當前資料庫

create database database_name;建立一個資料庫

drop database database_name;刪除一個資料庫

 

二:對錶的操作

DDL操作:資料定義語言 (Data Definition Language)

create table table_name(

id int primary key auto_increment,

name varchar(20),

);  建表語句

 

drop table table_name;刪除表的語句,直接把表的內容和表結構一併刪除。

truncate table table_name;刪除表的內容,保留表的結構,沒有復原,效率比較高。

delete from talbe_name;刪除表的內容,不刪除表的機構,效率比truncate低。

 

rename table old_name to new_name;修改表的名稱。

 

alter table table_name add column_name varchar(30);

alter table table_name drop column_name varchar(30);

alter table table_name modify colunm_name varchar(30);

 

desc table_name;查詢表結構

DML:資料操縱語言

delete from table_name where column_table=column_value;刪除條件下的資料

update table_name set column_name=‘‘,column=‘‘ where column_name=column_value;更新條件下的資料

insert into table_name (column_name1,column_name2...)values(column_values,column_values,...);

 

查詢語句:

select * from table_name where column_name=column_value;根據具體條件查詢滿足條件的資料

select a.column1,a.column2,...from table_name where column_name=column_value;根據條件查詢某些欄位的資料

後面還有子查詢,序列、視圖、索引。

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.