MySQL查詢以及修改表 表字段備註資訊

2021-08-22 13:36:41 字數 1452 閱讀 9437

在開發中,我們可能經常碰到這種問題,隨著需求的變更,或者設計階段的失誤,表字段的長度太小,欄位的備註資訊需要完善。所以,就要更改表結構或者其它一些資訊了。

話不多說,步入正題。

建立測試表:

create table student(

id int(11) primary key,

name varchar(50) comment '姓名',

age int(4) comment '年齡',

address varchar(50) comment '住址'

);

修改表備註資訊:

alter table student comment '學生資訊';

修改表字段長度:

alter table student modify column address varchar(100);
這裡需要注意的是:一般都是把字段長度調的更大,若是調小可能會影響現有資料。

修改表字段備註資訊:

alter table student modify column address varchar(50) comment '家庭住址';
給表增加新的字段:

alter table student add *** varchar(2) comment '性別';
在指定的列後面增加新的列

alter table student add address varchar(200) comment '家庭住址' after ***;
刪除表字段:

alter table student drop column ***;
檢視表的備註:

use information_schema;
information_schema是mysql資料庫中的系統庫,裡面存放了,使用者所建立的資料庫和表的資訊

select *

from tables

where table_schema = 'linxiaomi'(db name)

and table_name = 'student';

檢視表字段的備註:

use linxiaomi(db name);

show full columns from student(table name);

**:

修改表字段mysql語句

修改表字段 create table register id int primary key auto increment,name varchar 10 default null unique key,age tinyint unsigned default 18,registime timest...

Oracle修改表字段以及表型別

win7 oracle pl sql 一張表 lyz emp 建立表lyz emp create table lyz emp e id number 10 not null e oldname varchar2 2 not null primary key e id 測試表lyz emp是否建立成功...

mysql 修改 新增 刪除 表字段

mysql 修改 新增 刪除 表字段 新增表的字段 alter table 表名 add 欄位名 欄位的型別 例子 alter table table1 add transactor varchar 10 not null alter table table1 add id int unsigned...