mysql基礎 3 表的基本操作

2021-08-21 07:05:39 字數 1006 閱讀 9633

show tables;

建立乙個名為infor的表,注意id(約束是自增、主鍵、非空),性別用0,1表示。

create table infor(

id int auto_increment primary key not null,  

name varchar(10) not null,

age int not null,

gender bit default 1,

birthday datetime);

檢視表結構,以**格式返回。

desc infor;

以下infor為剛才建立的表名。

(1)修改表名

把表名由infor修改為student:

alter table infor rename to student;

(2)新增字段

(3)修改字段

可以修改字段型別、約束等,下面只是修改了型別:

alter table student modify column phone varchar(9);

(4)修改欄位名稱

把欄位名稱phone修改為number:

alter table student change column phone number varchar(9);

(5)刪除字段

Mysql表操作 基本操作

create table t5 id int,name varchar 10 show create table t5 create table t8 id int not null,name varchar 10 engine myisam default charset utf8 drop ta...

MySQL 3 資料表的基本操作

建立資料表 create table 表名 欄位名1,資料型別 列級別的約束條件 預設條件 表級別約束條件 在定義列的同時指定主鍵 欄位名 資料型別 primaey key 預設值 在定義完所有列之後指定主鍵 constrint 約束名 primary key 欄位名 定義多欄位聯合主鍵 prima...

mysql表基本操作

alter table empleey drop name2 alter table empleey add name2 varchar 100 alter table empleey modify column name varchar 2000 alter table empleey chang...