With the following script for SQL server 2012, can you write a query that will l
ID: 3827287 • Letter: W
Question
With the following script for SQL server 2012, can you write a query that will list the following...
Courses offered per term.
The script to use in SQL server...
USE [master]
GO
/****** Object: Database [tchesnav] Script Date: 4/17/2017 2:49:18 PM ******/
CREATE DATABASE [tchesnav]
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'tchesnav', FILENAME = N'c:Program FilesMicrosoft SQL ServerMSSQL11.SQLEXPRESSMSSQLDATA chesnav.mdf' , SIZE = 3136KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'tchesnav_log', FILENAME = N'c:Program FilesMicrosoft SQL ServerMSSQL11.SQLEXPRESSMSSQLDATA chesnav_log.ldf' , SIZE = 832KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
ALTER DATABASE [tchesnav] SET COMPATIBILITY_LEVEL = 110
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [tchesnav].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [tchesnav] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [tchesnav] SET ANSI_NULLS OFF
GO
ALTER DATABASE [tchesnav] SET ANSI_PADDING OFF
GO
ALTER DATABASE [tchesnav] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [tchesnav] SET ARITHABORT OFF
GO
ALTER DATABASE [tchesnav] SET AUTO_CLOSE ON
GO
ALTER DATABASE [tchesnav] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [tchesnav] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [tchesnav] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [tchesnav] SET CURSOR_DEFAULT GLOBAL
GO
ALTER DATABASE [tchesnav] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [tchesnav] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [tchesnav] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [tchesnav] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [tchesnav] SET ENABLE_BROKER
GO
ALTER DATABASE [tchesnav] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [tchesnav] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [tchesnav] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [tchesnav] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [tchesnav] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [tchesnav] SET READ_COMMITTED_SNAPSHOT OFF
GO
ALTER DATABASE [tchesnav] SET HONOR_BROKER_PRIORITY OFF
GO
ALTER DATABASE [tchesnav] SET RECOVERY SIMPLE
GO
ALTER DATABASE [tchesnav] SET MULTI_USER
GO
ALTER DATABASE [tchesnav] SET PAGE_VERIFY CHECKSUM
GO
ALTER DATABASE [tchesnav] SET DB_CHAINING OFF
GO
ALTER DATABASE [tchesnav] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )
GO
ALTER DATABASE [tchesnav] SET TARGET_RECOVERY_TIME = 0 SECONDS
GO
USE [tchesnav]
GO
/****** Object: Table [dbo].[Courses] Script Date: 4/17/2017 2:49:18 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Courses](
[CourseID] [int] NOT NULL,
[Subject] [varchar](50) NOT NULL,
[CourseNumber] [int] NOT NULL,
[Description] [varchar](200) NULL,
CONSTRAINT [PK_Courses] PRIMARY KEY CLUSTERED
(
[CourseID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[InstructorCourseSchedule] Script Date: 4/17/2017 2:49:18 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[InstructorCourseSchedule](
[AssignmentID] [int] NOT NULL,
[Term] [varchar](10) NOT NULL,
[InstructorID] [int] NOT NULL,
[CourseID] [int] NOT NULL,
[Credits] [int] NOT NULL,
[Meets] [datetime] NOT NULL,
CONSTRAINT [PK_InstructorCourseSchedule] PRIMARY KEY CLUSTERED
(
[AssignmentID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Instructors] Script Date: 4/17/2017 2:49:18 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Instructors](
[InstructorID] [int] NOT NULL,
[InstructorFirstName] [varchar](50) NOT NULL,
[InstructorLastName] [varchar](50) NOT NULL,
CONSTRAINT [PK_Instructors] PRIMARY KEY CLUSTERED
(
[InstructorID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[StudentEnrollment] Script Date: 4/17/2017 2:49:18 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StudentEnrollment](
[EnrollmentID] [int] NOT NULL,
[StudentID] [int] NOT NULL,
[AssignmentID] [int] NOT NULL,
[Grade] [nchar](2) NULL,
CONSTRAINT [PK_StudentEnrollment] PRIMARY KEY CLUSTERED
(
[EnrollmentID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Students] Script Date: 4/17/2017 2:49:18 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Students](
[StudentID] [int] IDENTITY(1,1) NOT NULL,
[StudentFirstName] [varchar](50) NOT NULL,
[StudentLastName] [varchar](50) NOT NULL,
[Address] [nvarchar](50) NULL,
[City] [nvarchar](50) NULL,
[State] [nchar](2) NOT NULL,
[Zip] [nvarchar](5) NOT NULL,
CONSTRAINT [PK_Students] PRIMARY KEY CLUSTERED
(
[StudentID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET IDENTITY_INSERT Students ON
INSERT Students (StudentID, StudentLastName, StudentFirstName, Address, City, State, Zip) VALUES
(1, 'Chesnavage', 'Timothy', '375 S Park St', 'Dallastown', 'PA', '17313'),
(2, 'Wentz', 'Carson', '11 Eagles Dr', 'Philadelphia', 'PA', '17212'),
(3, 'Sproles', 'Darren', '43 Philly St', 'Philadelphia', 'PA', '17222'),
(4, 'Matthews', 'Jordan', '81 Flyeagles Dr', 'Philadelphia', 'PA', '17818'),
(5, 'Ertz', 'Zach', '86 Touchdown St', 'Phiuladelphia', 'PA', '17077')
GO
INSERT StudentEnrollment (EnrollmentID, StudentID, AssignmentID, Grade) VALUES
(1, 1, 1, 'A'),
(2, 2, 2, 'A'),
(3, 3, 3, 'A'),
(4, 4, 4, 'A'),
(5, 5, 5, 'A')
GO
INSERT InstructorCourseSchedule (AssignmentID, Term, InstructorID, CourseID, Credits, Meets) VALUES
(1, 'Spring', 15, 1, 3, CAST ('2017-04-17 00:00:00' AS smalldatetime)),
(2, 'Spring', 16, 2, 3, CAST ('2017-04-17 00:00:00' AS smalldatetime)),
(3, 'Fall', 17, 3, 9, CAST ('2017-08-29 00:00:00' AS smalldatetime)),
(4, 'Fall', 18, 4, 9, CAST ('2017-08-29 00:00:00' AS smalldatetime)),
(5, 'Fall', 19, 5, 9, CAST ('2017-08-29 00:00:00' AS smalldatetime))
GO
INSERT Courses (CourseID, Subject, CourseNumber, Description) VALUES
(1, 'HOFB', 101, 'This course focuses on the history of American Football'),
(2, 'ROFB', 103, 'This course focuses on the rules of the game'),
(3, 'DEF', 105, 'This course focuses on the techniques of defensive football'),
(4, 'OFF', 106, 'This course focuses on the techniques of offensive football'),
(5, 'HTS', 201, 'This course focuses on techniques to score in football'),
(6, 'TO', 202, 'This course focuses on the use of timeouts in football'),
(7, 'HT', 205, 'This course focuses on the rules of halftime'),
(8, 'NFL', 308, 'This course focuses on the National Football League'),
(9, 'SCH', 410, 'This course focuses on how the scheduling works in the NFL'),
(10, 'PLT', 415, 'This course focuses on the penalties of football')
GO
INSERT Instructors (InstructorID, InstructorFirstName, InstructorLastName) VALUES
(15, 'Joe', 'Montana'),
(16, 'Peyton', 'Manning'),
(17, 'Eli', 'Manning'),
(18, 'Mike', 'Vick'),
(19, 'Joe', 'Flacco')
GO
ALTER TABLE [dbo].[InstructorCourseSchedule] WITH CHECK ADD CONSTRAINT [FK_InstructorCourseSchedule_Courses] FOREIGN KEY([CourseID])
REFERENCES [dbo].[Courses] ([CourseID])
GO
ALTER TABLE [dbo].[InstructorCourseSchedule] CHECK CONSTRAINT [FK_InstructorCourseSchedule_Courses]
GO
ALTER TABLE [dbo].[InstructorCourseSchedule] WITH CHECK ADD CONSTRAINT [FK_InstructorCourseSchedule_Instructors] FOREIGN KEY([CourseID])
REFERENCES [dbo].[Courses] ([CourseID])
GO
ALTER TABLE [dbo].[InstructorCourseSchedule] CHECK CONSTRAINT [FK_InstructorCourseSchedule_Instructors]
GO
ALTER TABLE [dbo].[StudentEnrollment] WITH CHECK ADD CONSTRAINT [FK_StudentEnrollment_InstructorCourseSchedule] FOREIGN KEY([AssignmentID])
REFERENCES [dbo].[InstructorCourseSchedule] ([AssignmentID])
GO
ALTER TABLE [dbo].[StudentEnrollment] CHECK CONSTRAINT [FK_StudentEnrollment_InstructorCourseSchedule]
GO
ALTER TABLE [dbo].[StudentEnrollment] WITH CHECK ADD CONSTRAINT [FK_StudentEnrollment_Students] FOREIGN KEY([StudentID])
REFERENCES [dbo].[Students] ([StudentID])
GO
ALTER TABLE [dbo].[StudentEnrollment] CHECK CONSTRAINT [FK_StudentEnrollment_Students]
GO
USE [master]
GO
ALTER DATABASE [tchesnav] SET READ_WRITE
GO
Explanation / Answer
Query:
select term, count(CourseID) [course Offered]
from InstructorCourseSchedule
group by Term;
This query will give you the number of courses offered each term.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.