MySQL之資料庫 資料表的增刪改查

2021-08-19 01:46:57 字數 1518 閱讀 3075

資料庫操作:

檢視所有資料庫:show databases;

使用資料庫:use 資料庫名;

檢視當前使用的資料庫:select database();

建立資料庫:create database 資料庫 charset=utf8; 例:create database jd charset=utf8;

刪除資料庫:drop database 資料庫名;  例 : drop database jd;

資料表操作:

create

table table_name(

column1 datatype contrai,

column2 datatype,

column3 datatype,

.....

columnn datatype,

primary key(one or more columns)

);

create

table classes(

idintunsigned auto_increment primary key

notnull,

name

varchar(10)

);

create

table students(

idintunsigned primary key auto_increment not

null,

name

varchar(20) default

'', age tinyint unsigned

default

0, height decimal(5,2),

gender enum('男','女','人妖','保密'),

cls_id int

unsigned

default

0)

alter table 表名 add 列名 型別; 例 : alter table students add birthday  date;

alter table 表名 rename 新錶名; 例: alter table students rename student;

alter table 表名 change 原名 新名  型別及約束。例:alter table students birthday birth date;

alter table 表名 modify 列名 型別及約束;

alter table students modify birth datetime not null;

alter table  表名 drop 列名;

alter table students drop birth;

drop table 表名;

drop table students;

show create table 表名;

例:show create table classes;

MySQL資料庫 資料表的增刪改查

mysql資料的增刪改查 crud 本文結構 一 增加 create 二 修改 update 三 查詢 retrieve 簡單查詢,下篇詳細展開 四 刪除 delete 首先,建立簡單的classes資料表和略微複雜的students資料表 id name age gender cls id bir...

mysql 資料庫 資料表,資料的增刪該查

mysql 的所有命令後面一定要加 切換資料庫 use 資料庫名字列出所有的資料庫 show databases建立資料庫 mysqladmin u root p create database1刪除資料庫 mysqladmin u root p drop database1建立資料庫 create...

MySQL 資料庫 資料表

1 檢視原始資料庫information schema中的表,並顯示出views表的字段結構屬性資訊 第一步 檢視所有的資料庫 show databases 如圖一 第二步 檢視information schema 內容 如圖二 第三步 檢視views 結構 如圖三 2 建立乙個offcn資料庫,並...