MySQL數據庫的基礎使用命令大全


show databases; 顯示所有已經存在的數據庫

create database test; 創建名字為test的數據庫

drop database test; 刪除名字為test的數據庫

use test;使用名字為test的數據庫

show tables; 顯示這個數據庫中的所有數據表

create table player(id int not null auto_increment primary key,name varchar(16) not null,level int not null default “0”,fightingValue int not null default “5”);創建一個名字為player的表,表里一共三列屬性id,name,level,fightingValue;

describe player; 顯示player這張表的屬性

select * from player 遍歷這張表的所有數據

insert into player (id,name,level,fightingValue)values (1,”法師”,1,10);增加一行數據

select name from player where id = 2; (查詢player這張表中id 為 2 這一行的名字信息)

select * from player order by level asc;對player這張表按等級排序(正序)

select * from player order by fightingValue desc;對player這張表按戰斗力排序(倒序)

delete from player where id = 1;刪除player這張表中的id = 1的一行數據

update player set fightingValue = 50 where id = 1;更新player這張表中id為1的玩家的戰斗力為50;

alter table player add column vipLevel int not null default “0”;增加player表中的一個vipLevel字段,類型為int;

alter table player drop vipLevel;刪除player表中的vipLevel字段

alter table player rename as player1;將player這張表的名字改為player1;

mySql支持的常用數據類型:

tinyint,int,varchar,char,float,double


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM