MySql常用操作SQL語句匯總_Mysql

來源:互聯網
上載者:User

MySQL的常見操作在這裡先做一下總結,已經整合到代碼裡面,經過檢驗無誤。

複製代碼 代碼如下:

/*建立一個資料庫*/
create database xuning_test;
/*說明當時使用資料庫物件*/
use xuning_test;
/*向資料庫中添加表並且定義表的結構*/
create table person(
 id int not null,
 name varchar(16) not null,
 sex varchar(16) not null,
 age int not null,
 address varchar(128) not null,
 remark varchar(512) not null
);
/*向資料庫的表中插入資料*/
insert into person value
 (1,'name_1','men',99,'beijing','This is a frindsheep boy'),
 (2,'name_2','men',88,'shanghai','ok great'),
 (1,'name_3','man',77,'guangzhou','This is lickly'),
 (1,'name_4','men',66,'beijing','This is a frindsheep boy'),
 (1,'name_5','men',55,'beijing','you dont going to shool'),
 (1,'name_6','man',44,'beijing','This is a frindsheep boy'),
 (1,'name_7','men',33,'beijing','This is a frindsheep boy'),
 (1,'name_8','man',22,'beijing',''),
 (1,'name_9','men',11,'beijing','This is a frindsheep boy')
;
/*查詢時否成功插入*/
select * from person;
/*下面是多種查詢方式*/
/*根據列的名稱屬性值*/
select name from person;
/*添加條件-根據性別*/
select name from person where sex = 'men';
/*也可以用比較符作為條件--一定逗號隔開*/
select name,address from person where age > 50;
/*看做對象去使用資料庫和表的關係=---雙表關聯--對象關係一定要明確*/
select xuning_test.person.name, xuning_test.person.id, xuning_test.person.age, xuning_test.person.address
from xuning_test.person, test1.test_xuning
where xuning_test.person.id = test1.test_xuning.id
;
/*使用表的別名進行查詢*/
use xuning_test;
select c.name,sex from person as c where c.age > 40 and c.address='beijing';

聯繫我們

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