更多SQL專業(yè)知識(shí)教程請(qǐng)點(diǎn)擊: SQL學(xué)習(xí)專題
這篇文章主要介紹了MySql常用操作SQL語句匯總,本文講解了增加、刪除、查詢、修改等常用SQL語句實(shí)例,需要的朋友可以參考下
MySQL的常見操作在這里先做一下總結(jié),已經(jīng)整合到代碼里面,經(jīng)過檢驗(yàn)無誤,
精心整理SQL常用操作語句匯總篇
。代碼如下:
/*創(chuàng)建一個(gè)數(shù)據(jù)庫*/
create database xuning_test;
/*說明當(dāng)時(shí)使用數(shù)據(jù)庫對(duì)象*/
use xuning_test;
/*向數(shù)據(jù)庫中添加表并且定義表的結(jié)構(gòu)*/
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
);
/*向數(shù)據(jù)庫的表中插入數(shù)據(jù)*/
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‘)
;
/*查詢時(shí)否成功插入*/
select * from person;
/*下面是多種查詢方式*/
/*根據(jù)列的名稱屬性值*/
select name from person;
/*添加條件-根據(jù)性別*/
select name from person where sex = ‘men‘;
/*也可以用比較符作為條件--一定逗號(hào)隔開*/
select name,address from person where age > 50;
/*看做對(duì)象去使用數(shù)據(jù)庫和表的關(guān)系=---雙表關(guān)聯(lián)--對(duì)象關(guān)系一定要明確*/
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
;
/*使用表的別名進(jìn)行查詢*/
use xuning_test;
select c.name,sex from person as c where c.age > 40 and c.address=‘beijing‘;
更多SQL專業(yè)知識(shí)教程請(qǐng)點(diǎn)擊: SQL學(xué)習(xí)專題