1. 程式人生 > >資料庫命令大全(也不是很全哈)

資料庫命令大全(也不是很全哈)

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