当前位置:Gxlcms > 数据库问题 > 数据库MySQL的创建

数据库MySQL的创建

时间:2021-07-01 10:21:17 帮助过:30人阅读

语言书写规范问题:

  1. 括号要分行
  2. 最后一行不需要逗号
  3. 外键时FK_Stuid1值需要改变,即不能重复
  4. 先创建不含外键的数据表,在创建含有外键的数据表

查询创建的数据库:

show databases;

查询表结构:

use school;
desc tb_student;

技术分享

增加数据信息:
#在学生姓名之后添加电话字段
use school;
alter table tb_student add `phone` varchar(15) after `SName`;

技术分享

#为表tb_student添加字段classid,并设置为外键。
use school;
alter table tb_student add deptId int(11) not null;
alter table tb_student add constraint `FK_dept_student` foreign key(`deptId`) references tb_dept(`id`);

技术分享

创建数据记录表:
use school;
insert into tb_dept(id,Local,Dnum) values 
(null,cy,1),
(null,qy,1),
(null,zy,1);

use school;
insert into tb_dept(id,Local,Dnum) values
(null,‘cy‘,‘1‘),
(null,‘ry‘,‘2‘),
(null,‘ty‘,‘3‘);

查询数据库:

SELECT Local,Dnum FROM tb_dept ORDER BY Dnum;

 


技术分享



 

数据库MySQL的创建

标签:结构   分享   creat   建表   ase   uid   gen   into   logs   

人气教程排行