JavaScript学习笔记(4) 约束

判断数据库是否存在,要是存在先删除改数据库,然后创建数据库,注意创建数据库后选择该数据库,然后开始创建表

drop schema if exists `sinaqbaza`;
create schema `sinaqbaza`;
use `sinaqbaza`;
create table `student`(
`id` int not null auto_increment,
`name` varchar(50) not null default '',
`birthday` date not null,
primary key(`id`)
);
-----------------今天学习的内容 查询,插入,修改  ----------------------
select * from `student`;            //查询
select `name` from `student`;       //查询
select `id`, `name`, `birthday` from `student`;
insert into `student`(`name`,`birthday`) value('Nurjan','1976-12-29');

select * from `student`;
select `name`,`birthday` from `student` where birthday>=2000-01-01;
select `name` from `student`;
select `id`, `name`, `birthday` from `student`;
insert into `student`(`name`,`birthday`) value('Nurjan','1976-12-29');
insert into `student`(`birthday`) value('1978-10-29');
update `student` set `birthday`='2006-01-12' where id=3;


-----------------------今天的学习内容   约束------------------------------------
 创建数据库的时候我们看过一个叫 B 的,就是binnary,就是把图片用二进制保存到数据库的技术,其实这种方式是不对的,
 UN 正整数的意思。这些都是表格内的约束,今天的内容是就是外键约束。
 两个或者以上表格内存在。
 
         use sinaqbaza;
        create table `teacher`(
        `id` int unsigned not null auto_increment,
        `teacherName` varchar(50) not null,
        `gender` tinyint(1) not null default 0,
        primary key(`id`)
        );
        create table `course`(
        `id` int unsigned not null auto_increment,
        `courseTitle` varchar(64) not null,
        `price` float unsigned not null default 0,
        `teacherId` int unsigned not null default 0,
        primary key(`id`),
        constraint `fk_teacher_id` foreign key(`teacherId`) references `teacher`(`id`)
        );
 

 

posted @ 2021-02-17 16:33  milanboy008  阅读(52)  评论(0)    收藏  举报