1. 程式人生 > >mysql 基本語法

mysql 基本語法

## 創建 刪除數據 修改列 數據庫操作 mar 基本 hang eba

#################################################################
#author: 陳月白
#_blogs: http://www.cnblogs.com/chenyuebai/
#################################################################

version: 5.7.17

--------------------------------------------------------------------------------------------------------------------------------------------
1.數據庫操作 創建庫:create database samp_db character set gbk; 刪除數據庫: drop database samp_db;
-------------------------------------------------------------------------------------------------------------------------------------------- 2.表操作
創建表
create table students
(
id int not null primary key,
name char
(12) not null, sex char(4) not null, age int not null, tel char(13) not null default - )
添加列
基本形式: alter table 表名 add 列名 列數據類型 [after 插入位置];
示例:在表的最後追加列 address: alter table students add address char(60);
在名為 age 的列後插入列 birthday: alter table students add birthday date after age;

修改列
基本形式: alter table
表名 change 列名稱 列新名稱 新數據類型; 示例:將表 tel 列改名為 telphone: alter table students change tel telphone char(13) default "-"; 將 name 列的數據類型改為 char(16): alter table students change name name char(16) not null; 刪除列 基本形式: alter table 表名 drop 列名稱; 示例:刪除 birthday 列: alter table students drop birthday; 重命名表 基本形式: alter table 表名 rename 新表名; 示例:重命名 students 表為 workmates: alter table students rename workmates; 刪除整張表 基本形式: drop table 表名; 示例: 刪除 workmates 表: drop table workmates; 刪除整個數據庫 基本形式: drop database 數據庫名; 示例: 刪除 samp_db 數據庫: drop database samp_db; -------------------------------------------------------------------------------------------------------------------------------------------- 3.數據操作 insert into students values(00001,陳月白,male,24,‘‘) INSERT into testdb.students(id,name,sex,age) VALUES (00003,李林,male,22) delete 語句用於刪除表中的數據, 基本用法為: delete from 表名稱 where 刪除條件; update 語句可用來修改表中的數據, 基本的使用形式為: update 表名稱 set 列名稱=新值 where 更新條件; select * from tablename where ...

mysql 基本語法