mysql基本文法總結,mysql基本文法

來源:互聯網
上載者:User

mysql基本文法總結,mysql基本文法
#建立表
CREATE DATABASE mytest
USE mytest
CREATE TABLE userInfo(
 userId INT PRIMARY KEY AUTO_INCREMENT NOT NULL, #auto_increment 為自動成長
 userSex INT(4) DEFAULT '0', #性別預設為0
 userAges DOUBLE(10,2) NOT NULL, #工資為double類型
 userName VARCHAR(20) NOT NULL,
 userPwd VARCHAR(20) NOT NULL
);




#向表中插入資料
INSERT INTO userInfo VALUES('',0,2000,'張三','123456'),('',0,4200,'李四','123456'),('',1,3000,'王五','123456')


#查詢表中的資料
SELECT * FROM userInfo;


#刪除表
DROP TABLE userInfo;
 
#查詢表名
DESC userInfo;


#查看錶 userInfo 中前2行資料
SELECT * FROM userInfo ORDER BY userId LIMIT 0,2;


#查看錶 userInfo 中前2行資料(與上相同)
SELECT * FROM userInfo LIMIT 0,2;


#刪除表 userInfo中編號為1的記錄
DELETE FROM userInfo WHERE userId=1;


#修改表 userInfo中編號為1的記錄
UPDATE userInfo SET userWages=4500 WHERE userId=2;


#在表userInfo中添加一個欄位userAge,類型為int(100)
ALTER TABLE userInfo ADD userAge INT(100);


#將表userInfo名字更改為stuClass
RENAME TABLE userInfo TO stuInfo;


#修改表userInfo列名
ALTER TABLE userInfo CHANGE userSex userSexs INT;


#修改表userInfo列名的類型
ALTER TABLE userInfo MODIFY userSex INT;


#刪除表userInfo中的列
ALTER TABLE userInfo DROP userWages;


#文章前面加入4個空格
update article set content=concat(' ',content);


#查詢當前使用的資料庫
SELECT DATABASE();
 
#當前資料庫包含的表資訊
SHOW TABLES;
 
#擷取目前時間
SELECT NOW();

相關文章

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.