1. 程式人生 > 其它 >mysql增刪改查命令

mysql增刪改查命令


1.幾個常見的資料型別


字元型:

char            0-256      定長字串
varchar         0-65535   變長字串
test            0-65535   長文字資料

數值型:
tinyint -128,127 小整數值
int -2147483,2147483647 大整數值
float 單精度浮點數值

日期型:
date 1000-01-01~9999—01-01 YYYY-MM-DD 日期值
time -838:59:59~838:59:59 HH:MM:SS 時間值
year 1902、2155 YYYY 年份值
datetime YYYY-MM-DD HH:MM:SS 混合日期和時間

列舉型
enum

2.增刪改查命令

增:

新增資料庫create database db_name;
新增表create table table_name;
給表新增名字(不為空),年齡,性別,出生日期
alter table table_name add (name char(10)not null,age tinyint(90),gender numn('' ‘女’),birth  date);

刪:

刪除資料庫drop database db_name;
刪除表drop table table_name;
刪除表中欄位alter table table_name drop 欄位名;

改:

修改表裡面的欄位名:alter table table_name change 原欄位名  新欄位名  欄位屬性;
修改欄位屬性alter table table_name modify 欄位名   新欄位屬性
修改表名rename table 舊錶名  to 新表名
修改資料庫名rename database  舊資料庫名  to 新資料庫名



查:

查詢所有資料庫     show databases;
查詢當前庫中的所有表   show tables;
查詢表詳情select * from table_name\G;
查詢表結構desc tablle_name;
查看錶狀態:select table status like table_name;
檢視資料庫中所有表狀態:show table status from db_name;
檢視建立的表:show create table table_name;
檢視使用者:select user();
切換資料庫:use db_name;

作業:1.基礎知識整理部落格

2.字元型別能否插入數值型別的記錄?

可以,

mysql> insert into test3 (name) values ('10');
Query OK, 1 row affected (0.00 sec)

日期時間型別能否插入數值型別的資料呢

不能

3.modifyint為char是否可以反之能否行得通

不可以,反之也不可以
4.修改date型別為int是否可以

不能
5.一個tinyint型別的欄位插入128這個數值看下結果

mysql> insert into test3 values ('money',128);
ERROR 1136 (21S01): Column count doesn't match value count at row 1