SQL語句操作ALTER

2022-02-08 12:42:21 字數 502 閱讀 9824

1、新增列:

alter table table_name add column_name datatype

例如:alter table student add name char(50)           //在student表中新增name欄位

2、刪除列:

alter table table_name drop column column_name        //有的資料庫為

3、修改列的資料型別:

alter table table_name alter column column_name datatype

例如:設定乙個表的主鍵:

先執行alter table 表名 alter column column_name int not null          //確保主鍵不為空,最好也是不同的

alter table temp add primary key(column_name)                   //新增主鍵

Alter語句使用介紹

需要修改庫表結構的時候,就用到alter語句,方法如下 alter table語句用於修改已經存在的表的設計。語法 alter table table add column field type size not null constraint index alter table table add...

ALTER 簡單操作 mysql

alter 語句 alter 語句用於在已有的表中新增 修改或刪除。刪除列 alter table 表名字 drop 列名稱 例如 刪除test111表中的age列 alter table test1111 drop age 新增列 新增到test1111表列,名為age,約束為not null 注...

mysql 基本操作 alter

檢視資料庫 show databases 新建資料庫 命令 create database 庫名字。選擇資料庫 use 2016test 建立表 create table 表名 欄位1,2,3.auto increment 自增 primary key 主鍵 檢視表結構 describe 表名 顯示...