Click here to Skip to main content
15,886,783 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have three tables like SCHOOL, ORIENTATION and SUBJECTS.
The tables have the following attributes
SQL
CREATE TABLE [dbo].[SCHOOL](
	[ID_chool] [int] IDENTITY(1,1) NOT NULL,
	[SchoolName] [nvarchar](50) NOT NULL,
	[AcademicYear] [nvarchar](15) NOT NULL,
	[Address] [nvarchar](50) NOT NULL,
	[ID_Person] [int] NOT NULL,
	[ID_Municipality] [int] NOT NULL,
 CONSTRAINT [PK_SCHOOL] PRIMARY KEY CLUSTERED 

SQL
CREATE TABLE [dbo].[ORIENTATION](
	[ID_Orientation] [int] IDENTITY(1,1) NOT NULL,
	[ID_School] [int] NOT NULL,
	[OrientationName] [nvarchar](50) NULL,
 CONSTRAINT [PK_ORIENTATION] PRIMARY KEY CLUSTERED

And the third table
SQL
CREATE TABLE [dbo].[SUBJECT](
	[ID_Subject] [int] IDENTITY(1,1) NOT NULL,
	[SubjectName] [nvarchar](50) NOT NULL,
	[ID_Orientation] [int] NOT NULL,
 CONSTRAINT [PK_SUBJECT] PRIMARY KEY CLUSTERED 


The problem is that the primary schools don't have ORIENTATIONS, so they don't need an OrientationName, only the secondary schools need an OrientationName.
How to solve this problem so I can register the subjects for primary schools.
P.S. My project has 15 tables, but I'm stuck in this problem and can't solve this problem by myself.
Thank you in advance for your reply.
Cheers.
Posted

1 solution

That doesn't seem to be a problem in isolation.

Why would the lack of "orientation" cause a problem? The only table which includes a school and an orientation is the orientation table - so just don't create a record!
Then allow nulls in the ID_Orientation field of the Subject table and you are fixed, aren't you?

Without data to indicate exactly what the problem is it's hard to work out why this is causing you difficulties! :laugh:
 
Share this answer
 
Comments
dr_iton 18-Nov-15 15:04pm    
If I allow nulls in the ID_Orientation field of Subject table how to know which subjects belong to which school. So through ID_Orientation I could know the School. Do I have to add another field on SUBJECT table to know the school, like ID_School or how to solve that.
The project I'm making it manages more than one school in one municipality for example.
Thank you
avanthi_k 18-Nov-15 16:59pm    
yes , you have to add another column Id_school for subject table to resolve this issue and just put NULL for ID_orientation whereever primary schools come
dr_iton 18-Nov-15 18:05pm    
Thank you all, problem solved.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900