现在的位置: 首页 > 综合 > 正文

mysql创建表以及相关内容

2018年02月03日 ⁄ 综合 ⁄ 共 688字 ⁄ 字号 评论关闭

-----建表----

create   table  student       

(id int  primary key,

name char(6) not null,

sex char(2),

age smallint

);

 

-----修改表---

(1)添加新列

Alter table student

add  email varchar(20) null;

如果向表中添加多个列:

Alter table student

add  email varchar(20) null,

add  phone varchr(12) not null;

 

(2) 修改表中的列

1 列名的修改

Exec sp_rename 'student.email', 'new_emal', 'column';

 

alter table student

alter column <列名> <新数据类型>;修改数据类型

drop column <列名> ; 删除列名

 

----修改表名---

rename  table  student to newstudent;

------删除表-----

Drop table student;


------当我们了解了数据库之后我们发现一种数据库可以有多重存储引擎,比如mysql就支持很多存储引擎,常用的有innodb ,myisam等,当我们选择不同的存储引擎时这个建立的表在存储方式,索引速度以及对事物的支持程度不同,所以存储引擎也叫做表类型。在建表的时候我们可以选择存储引擎。

 create table  tablename (id int , age int, score float)  engine="innodb"; 这里建立了一个存储引擎为innodb的表;--------

 

抱歉!评论已关闭.