溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

增刪改查MySQL簡(jiǎn)析

發(fā)布時(shí)間:2020-04-30 10:46:22 來(lái)源:億速云 閱讀:303 作者:三月 欄目:MySQL數(shù)據(jù)庫(kù)

下文主要給大家?guī)?lái)增刪改查MySQL簡(jiǎn)析,希望增刪改查MySQL簡(jiǎn)析能夠帶給大家實(shí)際用處,這也是我編輯這篇文章的主要目的。好了,廢話不多說(shuō),大家直接看下文吧。  

MySQL關(guān)系型數(shù)據(jù)庫(kù)RDS中的很基礎(chǔ)也很重要,增刪改查是MySQL入門(mén)的基礎(chǔ),數(shù)據(jù)庫(kù)吧來(lái)說(shuō)說(shuō)MySQL數(shù)據(jù)庫(kù)增刪改查常用語(yǔ)句。

  增刪改查語(yǔ)句:

  增:insert

  刪:delete

  改:update

  查:SELECT或者show

  庫(kù)操作:

  創(chuàng)建數(shù)據(jù)庫(kù):create database shujukuba;

  創(chuàng)建帶字符集的數(shù)據(jù)庫(kù):create database mydb2 CHARACTER SET=utf8;

  創(chuàng)建帶校驗(yàn)的數(shù)據(jù)庫(kù):create database mydb3 CHARACTER SET=utf8 COLLATE utf8_general_ci;

  顯示數(shù)據(jù)庫(kù):show databases;

  刪除數(shù)據(jù)庫(kù):DROP DATABASE shujukuba;

  修改數(shù)據(jù)庫(kù)編碼:ALTER DATABASE shujukuba character set gb2312;

  表操作:

  創(chuàng)建數(shù)據(jù)庫(kù)表(創(chuàng)建一個(gè)表名為:employee,該表中含有id、name、sex、birthday、job字段):

增刪改查MySQL簡(jiǎn)析

  create table employee(

  id int,

  name varchar(40),

  sex char(4),

  birthday date,

  job varchar(100),);

  表中增加image字段:alter table employee add image blob;修改job值,使其長(zhǎng)度為60(原長(zhǎng)度為1000):alter table employee modify job varchar(60);

  刪除sex列:alter table employee drop sex;表名改為user(原名employee):rename table employee to user;

  修改表的字符集為utf-8:alter table user character set utf8;

  列name修改為username:alter table user change column name username varchar(100);

  刪除表:drop table user;

  增刪改查實(shí)例準(zhǔn)備表:

  create table employee

  (

  id int,

  name varchar(40),

  sex varchar(4),

  birthday data,

  salary decimal(8,2),

  resume text

  );

  插入表數(shù)據(jù):

  insert into employee(id,name,sex,birthday,entry_date,salary,resume)values(1,‘zhangsan’,‘male’,‘1993-03-04’,‘2016-11-10’,‘1000’,‘i am a developer’);

  指定某些列插入數(shù)據(jù):insert into employee(id) values(6);

  插入漢字:insert into employee(id,name) values(6,‘張三’);

  修改表數(shù)據(jù):

  將所有員工薪水修改為5000元:update employee set salary=5000;將姓名為’zs’的員工薪水修改為3000元:update employee set salary = 3000 where name=‘zhangsan’;

  將姓名為’aaa’的員工薪水修改為4000元,job改為ccc:update employee set salary = 4000,job=‘ccc’ where name=‘張三’;

  將wu的薪水在原有基礎(chǔ)上增加1000元:update employee set salary = salary+1000 where name=‘張三’;

  刪除表數(shù)據(jù):

  刪除表中名稱為“zs”的記錄:delete from employee where job=‘ccc’;

  刪除表中所有記錄:delete from employee;

  使用truncate刪除表中記錄:truncate table employee;

  查詢表數(shù)據(jù):無(wú)錫渤海醫(yī)院 https://yyk.familydoctor.com.cn/20612/

  查詢表中所有學(xué)生的信息:select id,name,chinese,english,math from student;

  查詢表中所有學(xué)生的姓名和對(duì)應(yīng)的英語(yǔ)成績(jī):select name,english from student;

  查詢姓名為wu的學(xué)生成績(jī):select * from student where name=‘張三’;

  查詢英語(yǔ)成績(jī)大于90分的同學(xué):select * from student where english>‘90’;

  查詢英語(yǔ)分?jǐn)?shù)在 80-90之間的同學(xué):select * from student where english>=80 and english=<90;

  常見(jiàn)的MySQL語(yǔ)句命令:

  進(jìn)入mysql 命令行:mysql -uroot -p;

  查看所有數(shù)據(jù)庫(kù):show databases;

  創(chuàng)建數(shù)據(jù)庫(kù):create database niu charset utf8;

  刪除數(shù)據(jù)庫(kù):drop database niu;

  選擇數(shù)據(jù)庫(kù):use databases;

  查看所有表:show tables;

  查看創(chuàng)建數(shù)據(jù)庫(kù)的語(yǔ)句:show create database databasename;

  查看創(chuàng)建表的語(yǔ)句:show create table tablename;

  查看表結(jié)構(gòu):desc tablenmae;

  常見(jiàn)MySQL字段含義:

  自增長(zhǎng):auto_increment

  非空:not null

  默認(rèn)值:default

  唯一:unique

  指定字符集:charset

  主鍵:primary key

對(duì)于以上關(guān)于增刪改查MySQL簡(jiǎn)析,大家是不是覺(jué)得非常有幫助。如果需要了解更多內(nèi)容,請(qǐng)繼續(xù)關(guān)注我們的行業(yè)資訊,相信你會(huì)喜歡上這些內(nèi)容的。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI