0% found this document useful (0 votes)
28 views2 pages

Exercicio SQLpratico

The document creates a database called "faculdade" and defines tables to store information about students, professors, courses, and student grades. It defines the structure of each table including data types and primary/foreign keys. It then populates the tables with sample data by executing several INSERT statements.

Uploaded by

Diogo Monte
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Exercicio SQLpratico

The document creates a database called "faculdade" and defines tables to store information about students, professors, courses, and student grades. It defines the structure of each table including data types and primary/foreign keys. It then populates the tables with sample data by executing several INSERT statements.

Uploaded by

Diogo Monte
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

create database faculdade;

use faculdade;

create table aluno (

matricula INT primary key,

nome varchar(500) not null,

telefone numeric(9));

create table professor (

matricula INT,

nome varchar(500) not null,

constraint matricula_pk PRIMARY KEY (matricula));

create table disciplina (

codigo int primary key, nome varchar(500) not null,


carga_horaria int not null, matricula_professor int not null,

constraint carga_chk CHECK (carga_horaria > 0), constraint matricula_prof_fk FOREIGN KEY
(matricula_professor) references professor(matricula));

create table aluno_disciplina (

matricula_aluno INT,

codigo_disciplina int,

nota_final numeric(5, 2) not null,

constraint nota_chk CHECK (nota_final > 0 and nota_final < 10),

constraint chave_pk PRIMARY KEY (matricula_aluno, codigo_disciplina),

constraint mat_aluno_fk FOREIGN KEY (matricula_aluno) references aluno(matricula),

constraint cod_disc_fk FOREIGN KEY (codigo_disciplina) references disciplina(codigo)

);

INSERT INTO aluno values (12345, 'Joao Henrique Martins', 998765432);

INSERT INTO aluno values (12121, 'Neymar Messi Cristiano', 997451245);

INSERT INTO aluno values (89898, 'Gabriel Caldas Brandao', 987845120);

INSERT INTO aluno values (45454, 'Joaquim Jose Silva', 999995645);

INSERT INTO aluno values (53636, 'Diogo Mysql Python', 998001200);


INSERT INTO professor values (070, 'Mario Quintas');

INSERT INTO professor values (071, 'Barbosa Barbudo');

INSERT INTO professor values (072, 'Seu Barriga Mole');

INSERT INTO professor values (073, 'Prof.Dr.Mestre Juan');

INSERT INTO disciplina values (123, 'Banco de Dados', 5, 070);

INSERT INTO disciplina values (456, 'Python', 6, 071);

INSERT INTO disciplina values (678,'Java', 4, 072);

INSERT INTO disciplina values (900, 'C++', 5, 073);

INSERT INTO aluno_disciplina values (12345, 123, 9);

INSERT INTO aluno_disciplina values (12345, 456, 8);

INSERT INTO aluno_disciplina values (12121, 456, 7);

INSERT INTO aluno_disciplina values (12121, 900, 7);

INSERT INTO aluno_disciplina values (89898, 123, 8);

INSERT INTO aluno_disciplina values (89898, 678, 8);

INSERT INTO aluno_disciplina values (45454, 900, 3);

INSERT INTO aluno_disciplina values (45454, 123, 5);

INSERT INTO aluno_disciplina values (53636, 123, 10);

INSERT INTO aluno_disciplina values (53636, 456, 10);

You might also like