數據庫表的定義和修改操作


下面的語句全部用小寫表示,方便記憶。剛學了入門的一些語句如下:

1.創建一個數據庫schoolInfo

create database schoolInfo;

2.創建teacherInfo表

 1 create table teachInfo(
 2 
 3 id int(4) not null unique primary key auto_increment,#主鍵
 4 
 5 num int(10) not null unique,#唯一鍵
 6 
 7 Name varchar(20) not null,#可變長度的字符串
 8 
 9 Sex varchar(4) not null,
10 
11 Birthday datetime,#日期時間類型,范圍從公元1753年1月1日00:00:00.000 到9999年12月31日23:59:59.997 
12 
13 Address varchar(50)
14 
15 );

3.將teacherInfo表的name字段的數據類型改為varchar(30)

alter table teacherInfo modify name varchar(30) not null;

4.將birthday字段的位置改到sex字段的前面

alter table teacherInfo modify birthday datetime after name;

5.將num字段改名為t_id

alter table teacherInfo change num t_id int(10) not null;

6.將teacherInfo 表的address字段刪除

alter table teacherInfo drop address;

7.在teacherInfo表中增加名為wages的字段,數據類型為float

alter table teacherInfo add wages float;

8.將teacherInfo表改名為teacherInfo Info

alter table teacherInfo rename teacherInfo_Info;

9.將teacherInfo 表的存儲引擎更改為MyISAM類型

alter table teacherInfo engine=MyISAM;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM