When deleting an entry indicated in another table, how do I know when to stop?

I have the following table structure in my database:

create table Encargado(
ID int primary key,
Nombre varchar(300),
)

create table Area(
ID int primary key,
Nombre varchar(300),
Jefe int foreign key references Encargado(ID)
)

create table Carrera(
ID int primary key,
Nombre varchar(300),
Area int foreign key references Area(ID)
)

create table Formacion(
ID int primary key,
Grado varchar(300),
Lugar varchar(300)
)

create table Docente(
ID int primary key,
Nombre varchar(300),
Carrera int foreign key references Carrera(ID),
Formacion int foreign key references Formacion(ID),
Horario varchar(300)
)

create table Evaluacion(
ID int primary key,
Docente int foreign key references Docente(ID),
Evaluador varchar(300),
Secuencia int,
Pizarra int,
Audiovisual int,
Letra int,
Voz int,
GestosVocabulario int,
Ejemplificacion int,
Respuestas int,
DominioEscenico int,
Participacion int,
Observacion varchar(4000),
Materias varchar(3000),
Valido bit
)

create table Seguimiento(
ID int primary key,
Docente int foreign key references Docente(ID),
Modulo int,
Semestre int,
Ano int,
Fecha datetime,
Hora datetime,
OrdenSecuencia bit,
OrdenSecuenciaObservacion varchar(200),
PortafolioAlumno bit,
PortalofioAlumnoObservacion varchar(200),
AspectosParaEntrevista varchar(3000),
Conclusiones varchar(3000),
Evaluador varchar(300),
DirectorDeArea int foreign key references Encargado(ID),
EncargadoControl int foreign key references Encargado(ID),
)

Say I want to delete an area, how would I do it? I will also need to remove all Carreras, as well as all the docents.

public void Delete(Area area)
        {
            db.Carreras.DeleteAllOnSubmit(area.Carreras);
            //I'm stuck here. Is this what I should be doing?
        }

Can anyone suggest how to handle this?

I am using C # and Linq-to-SQL. I feel like I may have dug myself in a hole using this table structure or perhaps one of the downturns of a relational database?: \

+3
source share
4 answers

Linq-to-SQL, , .

, Oracle ON DELETE CASCADE create table, .

, . , , , Linq-To-SQL, JAVA, ROR, PHP .., , , .

+2
+1

, , ? Carreras, Docentes.

, (DRI) ON DELETE NO ACTION (.. , ) CASCADE (.. ).

, , (, Carrera.Area) NOT NULL.

:

CREATE TABLE Carrera
(
...
Area INTEGER NOT NULL
   REFERENCES Area (ID) 
   ON DELETE CASCADE
);

CREATE TABLE Docente
(
...
Carrera INTEGER NOT NULL
   REFERENCES Carrera (ID)
   ON DELETE CASCADE, 
...
);

, , ,

Evaluacion REFERENCES Docente
Seguimiento REFERENCES Docente

, ON DELETE CASCADE DRI.

Seguimiento REFERENCES Encargado -- twice
Area REFERENCES Encargado

, . ON DELETE CASCADE DRI (, SQL Server), "" .

- , , , NULLable ( ...?), ON DELETE SET NULL DRI. , NULLable, , :)

0

" " ?

, ( ) , .

: , . . , . , , .

: (Active = Y/N) , ( - ), "Active = N" , , "" .

0

Source: https://habr.com/ru/post/1755876/


All Articles