標籤:
1.show databases; 顯示所有資料庫
2.create database 資料庫名 [其他選項]; 建立資料庫
例:create database example_db character set gbk; 建立了一個名為example_db的資料庫,並將資料庫字元編碼指定為gbk,便於在命令提示字元下顯示中文。
3.use 資料庫名; 選擇要用的資料庫
4.show tables; 顯示已選擇的資料庫中的所有表
5.create table 表名(列名 資料類型,........); 建立表
例:create table students(
id int not null primary key,
name char(8) not null,
password varchar(20)
);
6.alter table 表名 add 要插入的列名稱 資料格式 [after 插入位置];; 在建好的表中插入一列
例:alter table students add tel varchar(13) after password;
7.alter table 表名 drop column 要刪除的列名稱; 在建好的表中刪除一列
例:alter table students drop column tel;
8.insert 【into】 表名(列名1,列名2,......)values(列值1,列值2,......); 在表中插入資料
例:insert into students(id,name) values(01,‘李明‘);
或 insert students values(01,‘李明‘,‘qwe123‘);
9.select * from 表名 where 查詢條件; 查詢滿足條件的表中的所有資訊
select 列名 from 表名 where 查詢條件; 查詢滿足條件的所有列資訊
例:select id,name from students;
10.update 表名 set 列名=新值 where 更新條件; 修改表中的資料
例:update students set id=id+1 where name=‘李明‘;
11.delete from 表名 where 刪除條件;
例:delete from students where name=‘李明‘;
12.drop table 表名; 刪除整張表
13.drop database 資料庫名; 刪除整個資料庫
14.alter table 表名 change 列名 列新名稱 新資料類型; 修改列
例:alter table students change password password char(10) not null;
15.alter table 表名 rename 新表名; 重新命名表
註:參考http://www.cnblogs.com/mr-wid/archive/2013/05/09/3068229.html
mySQL筆記(1)