title: Creating a time table using SQL
body: <p>I want to create a time table for my university's modules in SQL Server Management Studio using a query.</p>
  
  <p>This is my first time programming in SQL and don't know much about it. I have created the database as well as the tables I want to use, using the following code:</p>
  
  <pre><code>USE master
  GO
  
  IF EXISTS (SELECT * FROM sys.databases WHERE name = 'myTimetable') 
      DROP DATABASE myTimetable 
  GO
  
  CREATE DATABASE myTimetable 
  GO
  
  USE myTimetable
  GO
  
  CREATE TABLE DayTable 
  (
      WeekDay_ID int Identity (1,1) PRIMARY KEY NOT NULL,  
      Day_Name varchar(10) NOT NULL
  )
  GO
  
  CREATE TABLE TimeRangeTable 
  (
      DayTime_ID int Identity (1,1) PRIMARY KEY NOT NULL, 
      TimeInterval varchar(20) NOT NULL
  )
  GO
  
  
  CREATE TABLE SubjectTable 
  (
      Course_ID int Identity (1,1) PRIMARY KEY NOT NULL, 
      CourseCode varchar (10), 
      CourseName varchar (255) NOT NULL 
  )
  GO
  
  CREATE TABLE ScheduleTable 
  (
      WeekDay_ID int references DayTable(WeekDay_ID),
      DayTime_ID int references TimeRangeTable(DayTime_ID), 
      Course_ID int references SubjectTable(Course_ID), 
  )
  GO
  </code></pre>
  
  <p>The tables was created correctly and I managed to insert the correct data into the tables, except for my <code>ScheduleTable</code> (the last table created in the above sample code).</p>
  
  <p>Here is the SQL code I used to insert the data:</p>
  
  <pre><code>insert into DayTable values ('Monday')
  insert into DayTable values ('Teusday')
  insert into DayTable values ('Wensday')
  insert into DayTable values ('Thursday')
  insert into DayTable values ('Friday')
  insert into DayTable values ('Saterday')
  insert into DayTable values ('Sunday')
  
  insert into TimeRangeTable values ('07:30 - 08:20')
  insert into TimeRangeTable values ('08:30 - 09:20')
  insert into TimeRangeTable values ('09:30 - 10:20')
  insert into TimeRangeTable values ('10:30 - 11:20')
  insert into TimeRangeTable values ('11:30 - 12:20')
  insert into TimeRangeTable values ('12:30 - 13:20')
  insert into TimeRangeTable values ('13:30 - 14:20')
  insert into TimeRangeTable values ('14:30 - 15:20')
  insert into TimeRangeTable values ('15:30 - 16:20')
  insert into TimeRangeTable values ('16:30 - 17:20')
  insert into TimeRangeTable values ('17:30 - 18:20')
  
  insert into SubjectTable values ('WTW115','Discrete Mathematics')
  insert into SubjectTable values ('INF214','Database Design')
  insert into SubjectTable values ('INL210','Information Seeking and Retreival')
  insert into SubjectTable values ('INL240','Social and Ethical Impact')
  insert into SubjectTable values ('INF271','System Analysis and Design')
  insert into SubjectTable values ('INF154','Introduction to Programming')
  
  -- Struling from this point onward...
  insert into ScheduleTable values('1','1','1')
  insert into ScheduleTable values('1','2','2')
  insert into ScheduleTable values('1','3','3')
  insert into ScheduleTable values('1','4','3')
  insert into ScheduleTable values('1','5','3')
  insert into ScheduleTable values('2','4','1')
  insert into ScheduleTable values('2','5','2')
  insert into ScheduleTable values('2','6','2')
  insert into ScheduleTable values('2','9','4')
  insert into ScheduleTable values('2','10','2')
  insert into ScheduleTable values('3','1','5')
  insert into ScheduleTable values('3','2','5')
  insert into ScheduleTable values('3','6','1')
  insert into ScheduleTable values('3','7','3')
  insert into ScheduleTable values('4','1','4')
  insert into ScheduleTable values('4','3','5')
  </code></pre>
  
  <p>It all executes and inserts the data, but when I display the data for <code>ScheduleTable</code>, is shows the data as Follow:</p>
  
  <pre><code>      WeekDay_ID    DayTime_ID    Course_ID
  -------------------------------------------
   1    1             1             1
   2    1             2             2
   3    1             3             3
   4    1             4             3
   5    1             5             3
   6    2             4             1
   7    2             5             2
   8    2             6             2
   9    2             9             4
   10   2             10            2
   11   3             1             5
   12   3             2             5
   13   3             6             1
   14   3             7             3
   15   4             1             4
   16   4             3             5
  </code></pre>
  
  <p>Where I wanted it to show the data instead of just the codes, example of what I wanted:</p>
  
  <pre><code>      WeekDay_ID    DayTime_ID     Course_ID
   --------------------------------------------
   1    Monday        07:30 - 08:20  WTW115
   2    Monday        08:30 - 09:20  INF214
   3    Monday        09:30 - 10:20  INL210
   4    Monday        10:30 - 11:20  INL210
   5    Monday        11:30 - 12:20  INL210
   etc...
  </code></pre>
  
  <p>I know it has something to do with my Schedule table but that is all I know I don't know how to display it in this way as in the example.</p>
  
  <p>Any help will be appreciated.</p>