Базы данных
Введение
ФИО,Предмет,Оценка Иванов И.И.,Java,4 Иванов И.И.,Базы данных,5 Петров П.П.,Java,5 Петров П.П.,Базы данных,4
ФИО Предмет Оценка String, 14 String, 12 Number, 1 Иванов И.И. Java 4 Иванов И.И. Базы данных 5 Петров П.П. Java 5 Петров П.П. Базы данных 4
create database CTD;
use CTD;
create table Groups ( group_id int, group_no char(6) ); create table Students ( student_id int, name varchar(50), group_id int );
insert into Groups (group_id, group_no) values (1, 'M34351'), (2, 'M34391'); insert into Students (student_id, name, group_id) values (1, 'Alexey Grunsky', 2), (2, 'Vitaly Egorov', 2), (3, 'Elvira Minko', 1);
select group_id, group_no from Groups;
select student_id, name, group_id from Students;
select name, group_no from Students natural join Groups;
select Students.name, Groups.group_no from Students inner join Groups on Students.group_id = Groups.group_id;
update Students set group_id = 1 where student_id = 2;
update Students set group_id = 1 where name = 'Vitaly Egorov';
insert into Groups (group_id, group_no) values (1, 'M34311');
delete from Groups where group_no = 'M34311';
alter table Groups add constraint group_id_unique unique (group_id);
update Students set group_id = 5 where student_id = 2;
update Students set group_id = 1 where student_id = 2;
alter table Students add foreign key (group_id) references Groups (group_id);