02 資料表的操作

2022-09-11 02:39:13 字數 1503 閱讀 8356

資料表的操作

-- 檢視當前資料庫中所有表

show tables;

-- 建立表

-- int unsigned 無符號整形

-- auto_increment 表示自動增長

-- not null 表示不能為空

-- primary key 表示主鍵

-- default 預設值

-- create table 資料表名字 (字段 型別 約束[, 字段 型別 約束]);

create table yyy (

id int unsigned not null auto_increment primary key,

name varchar(20) not null

);-- 建立 classes 表(id、name)

create table classes (

id int unsigned not null auto_increment primary key,

name varchar(20) not null

);-- 建立 students 表(id、name、age、high (decimal)、gender (enum)、cls_id)

create table students (

id int unsigned not null auto_increment primary key,

name varchar(20) not null,

age int unsigned not null,

high decimal(5,2),

gender enum("男","女","保密") default "保密",

cls_id int unsigned

);-- 檢視表的建立語句

-- show create table 表名字;

show create table yyy;

-- 修改表-新增字段 mascot (吉祥物)

-- alter table 表名 add 列名 型別;

alter table yyy add jixiangwu varchar(20);

0-- 修改表-修改字段:不重新命名版

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

alter table yyy modify jixiangwu varchar(30);

-- 修改表-修改字段:重新命名版

-- alter table 表名 change 原名 新名 型別及約束;

alter table yyy change jixiangwu mascot varchar(20);

-- 修改表-刪除字段

-- alter table 表名 drop 列名;

alter table yyy drop mascot;

-- 刪除表

-- drop table 表名;

-- drop database 資料庫;

資料表的操作

表是組成資料庫的基本的元素 表的基本操作有 建立 檢視 更新 刪除。表中的資料庫物件包含列 索引 觸發器。列 屬性列,建立表時指定的名字和資料型別,索引 根據制定的資料庫表建立起來的順序,提供了快速訪問資料的途徑且可以監督表的資料 觸發器 指使用者定義的事務命令集合,當對乙個表中的資料進行插入 更行...

資料表的操作

1.顯示所有的資料表 mysql show tables from 資料庫名 2.顯示表結構 mysql desc 表名 或者 describe 表名 3.顯示資料表建立語句 mysql show create table 表名 mysql show create table 表名 g 可以更清晰的...

資料表操作

1 建立資料表 create table if not exists table name column name data type,2 檢視資料表 show tables show tables from mysql 3 檢視資料表結構 show columns from tbl name 4 ...