Create a new database and execute the code below in SQL Server’s query window to create the database tables.
CREATE TABLE PhysicianSpecialties
(SpecialtyID integer,
SpecialtyName varchar(50),
CONSTRAINT PK_PhysicianSpecialties PRIMARY KEY (SpecialtyID))
go
CREATE TABLE ZipCodes
(ZipCode varchar(10),
City varchar(50),
State varchar(2),
CONSTRAINT PK_ZipCodes PRIMARY KEY (ZipCode))
go
CREATE TABLE PhysicianPractices
(PracticeID integer,
PracticeName varchar(50),
Address_Line1 varchar(50),
Address_Line2 varchar(50),
ZipCode varchar(10),
Phone varchar(14),
Fax varchar(14),
WebsiteURL varchar(50),
CONSTRAINT PK_PhysicianPractices PRIMARY KEY (PracticeID),
CONSTRAINT FK_PhysicianPractices_ZipCodes FOREIGN KEY (ZipCode) REFERENCES Zipcodes)
go
CREATE TABLE Physicians
(PhysicianID integer,
FirstName varchar(40),
LastName varchar(50),
PracticeID integer,
SpecialtyID integer,
Email varchar(50),
CONSTRAINT PK_Physicians PRIMARY KEY (PhysicianID),
CONSTRAINT FK_Physicians_Practices FOREIGN KEY (PracticeID) REFERENCES PhysicianPractices,
CONSTRAINT FK_Physicians_PhysicianSpecialities FOREIGN KEY (SpecialtyID) REFERENCES PhysicianSpecialties)
go
CREATE TABLE Patients
(PatientID integer,
FirstName varchar(50),
MiddleInitial varchar(1),
LastName varchar(50),
Address_Line1 varchar(50),
Address_Line2 varchar(50),
ZipCode varchar(10),
Phone_Home varchar(14),
Phone_Alternate varchar(14),
Email varchar(50),
CONSTRAINT PK_Patients PRIMARY KEY (PatientID))
go
CREATE TABLE Referrals
(ReferralID integer,
StartDate smalldatetime,
EndDate smalldatetime,
PatientID integer,
PhysicianID integer,
CONSTRAINT PK_Referrals PRIMARY KEY (ReferralID),
CONSTRAINT FK_Referrals_Patients FOREIGN KEY (PatientID) REFERENCES Patients,
CONSTRAINT FK_Referrals_Physicians FOREIGN KEY (PhysicianID) REFERENCES Physicians)
go
CREATE TABLE Services
(ServiceID integer,
ServiceName varchar(50),
CONSTRAINT PK_ServiceID PRIMARY KEY (ServiceID))
go
CREATE TABLE Frequencies
(FrequencyID integer,
Frequency varchar(30),
CONSTRAINT PK_Frequencies PRIMARY KEY (FrequencyID))
go
CREATE TABLE ReferralServices
(ReferralID integer,
ServiceID integer,
FrequencyID integer,
CONSTRAINT PK_ReferralServices PRIMARY KEY (ReferralID, ServiceID),
CONSTRAINT FK_ReferralServices_Referrals FOREIGN KEY (ReferralID) REFERENCES Referrals,
CONSTRAINT FK_ReferralServices_Services FOREIGN KEY (ServiceID) REFERENCES Services,
CONSTRAINT FK_ReferralServices_Frequencies FOREIGN KEY (FrequencyID) REFERENCES Frequencies)
go
CREATE TABLE PaymentTypes
(PaymentTypeID integer,
PaymentType varchar(25),
CONSTRAINT PK_PaymentTypes PRIMARY KEY (PaymentTypeID))
go
CREATE TABLE InsuranceCompanies
(InsuranceID integer,
InsuranceCompany varchar(50),
Address_Line1 varchar(50),
Address_Line2 varchar(50),
ZipCode varchar(10),
Phone varchar(15),
Fax varchar(15),
Email varchar(50),
CONSTRAINT PK_InsuranceCompanies PRIMARY KEY (InsuranceID),
CONSTRAINT FK_InsuranceCompanies_ZipCodes FOREIGN KEY (ZipCode) REFERENCES ZipCodes)
go
CREATE TABLE Contracts
(ContractID integer,
ReferralID integer,
StartDate smalldatetime,
EndDate smalldatetime,
PaymentTypeID integer,
InsuranceID integer,
NegotiatedRate float,
CONSTRAINT PK_Contracts PRIMARY KEY (ContractID),
CONSTRAINT PK_Contracts_Referrals FOREIGN KEY (ReferralID) REFERENCES Referrals,
CONSTRAINT FK_Contracts_PaymentTypes FOREIGN KEY (PaymentTypeID) REFERENCES PaymentTypes,
CONSTRAINT FK_Contracts_InsuranceCompanies FOREIGN KEY (InsuranceID) REFERENCES InsuranceCompanies)
go
CREATE TABLE EmployeeTypes
(EmployeeTypeID integer identity,
EmployeeType varchar(25),
CONSTRAINT PK_EmployeeTypes PRIMARY KEY (EmployeeTypeID))
go
CREATE TABLE EmployeeTitles
(EmployeeTitleID integer,
EmployeeTitle varchar(30),
CONSTRAINT PK_EmployeeTitles PRIMARY KEY (EmployeeTitleID))
go
CREATE TABLE EmployeeSkillLevels
(SkillLevelID integer,
SkillLevel varchar(15),
CONSTRAINT PK_EmployeeSkillLevels PRIMARY KEY (SkillLevelID))
go
CREATE TABLE BillingRates
(EmployeeTypeID integer,
SkillLevelID integer,
BillingRate float,
CONSTRAINT PK_PrimaryKey PRIMARY KEY (EmployeeTypeID, SkillLevelID),
CONSTRAINT FK_BillingRates_EmployeeTypes FOREIGN KEY (EmployeeTypeID) REFERENCES EmployeeTypes,
CONSTRAINT FK_BillingRates_EmployeeSkillLevels FOREIGN KEY (SkillLevelID) REFERENCES EmployeeSkillLevels)
go
CREATE TABLE EmployeeRanks
(RankID integer,
EmployeeTypeID integer,
TitleID integer,
SkillLevelID integer,
HourlyRate float,
Salary float,
CONSTRAINT PK_EmployeeRanks PRIMARY KEY (RankID),
CONSTRAINT FK_EmployeeRanks_EmployeeTypes FOREIGN KEY (EmployeeTypeID) REFERENCES EmployeeTypes,
CONSTRAINT FK_EmployeeRanks_EmployeeTitles FOREIGN KEY (TitleID) REFERENCES EmployeeTitles,
CONSTRAINT FK_EmployeeRanks_EmployeeSkillLevels FOREIGN KEY (SkillLevelID) REFERENCES EmployeeSkillLevels)
go
CREATE TABLE Employees
(EmployeeID integer,
FirstName varchar(30),
MiddleInitial varchar(1),
LastName varchar(50),
Address_Line1 varchar(50),
Address_Line2 varchar(50),
ZipCode varchar(10),
Phone varchar(14),
Cell_Phone varchar(14),
Email varchar(50),
RankID integer,
HourlyWage float,
Salary float,
CONSTRAINT PK_Employees PRIMARY KEY (EmployeeID),
CONSTRAINT FK_Employees_EmployeeRanks FOREIGN KEY (RankID) REFERENCES EmployeeRanks,
CONSTRAINT FK_Employee_ZipCodes FOREIGN KEY (ZipCode) REFERENCES ZipCodes)
go
CREATE TABLE Shifts
(ShiftID integer,
ShiftName varchar(20),
StartTime time,
EndTime time,
CONSTRAINT PK_Shifts PRIMARY KEY (ShiftID))
go
CREATE TABLE DaysOfWeek
(DayOfWeekID integer,
DayOfWeek varchar(15),
CONSTRAINT PK_DaysOfWeek PRIMARY KEY (DayOfWeekID))
go
CREATE TABLE Availability
(EmployeeID integer,
WeekOf smalldatetime,
DayOfWeekID integer,
ShiftID integer,
CONSTRAINT PK_Availability PRIMARY KEY (EmployeeID, WeekOf, DayOfWeekID, ShiftID),
CONSTRAINT FK_Availability_Employees FOREIGN KEY (EmployeeID) REFERENCES Employees,
CONSTRAINT FK_Availability_DaysOfWeek FOREIGN KEY (DayOfWeekID) REFERENCES DaysOfWeek,
CONSTRAINT FK_Availability_Shifts FOREIGN KEY (ShiftID) REFERENCES Shifts)
go
CREATE TABLE MedicalSuppliers
(SupplierID integer,
SupplierName varchar(50),
Address_Line1 varchar(50),
Address_Line2 varchar(50),
ZipCode varchar(10),
Phone varchar(14),
Fax varchar(14),
Email varchar(50),
CONSTRAINT PK_MedicalSuppliers PRIMARY KEY (SupplierID),
CONSTRAINT FK_MedicalSuppliers_ZipCodes FOREIGN KEY (ZipCode) REFERENCES ZipCodes)
go
CREATE TABLE Supplies
(SupplyID integer,
SupplyDescription varchar(40),
ChargePerUnit float,
CONSTRAINT PK_Supplies PRIMARY KEY (SupplyID))
go
CREATE TABLE SupplyInventory
(SupplyID integer,
SupplierID integer,
DateReceived smalldatetime,
UnitCost float,
Quantity float,
CONSTRAINT PK_SupplyInventory PRIMARY KEY (SupplyID, SupplierID, DateReceived),
CONSTRAINT FK_SupplyInventory_Supplies FOREIGN KEY (SupplyID) REFERENCES Supplies,
CONSTRAINT FK_SupplyInventory_Suppliers FOREIGN KEY (SupplierID) REFERENCES MedicalSuppliers)
go
CREATE TABLE Visits
(VisitID integer,
DateRendered smalldatetime,
StartTime time,
EndTime time,
EmployeeID integer,
PatientID integer,
CONSTRAINT PK_Visits PRIMARY KEY (VisitID),
CONSTRAINT FK_Visits_Employees FOREIGN KEY (EmployeeID) REFERENCES Employees,
CONSTRAINT FK_Visits_Patients FOREIGN KEY (PatientID) REFERENCES Patients)
go
CREATE TABLE VisitDetails
(VisitID integer,
VisitDetailID integer,
SupplyID integer,
SupplyQuantity integer,
ServiceID integer,
Charge float,
CONSTRAINT PK_VisitDetails PRIMARY KEY (VisitID, VisitDetailID),
CONSTRAINT FK_VisitDetaiils_Supplies FOREIGN KEY (SupplyID) REFERENCES Supplies,
CONSTRAINT FK_VisitDetails_Services FOREIGN KEY (ServiceID) REFERENCES Services)
go
|
2. Display a list of all patients who have an alternate/cell phone number |
Patient First Name, followed by a space, followed by the patient’s last name. (e.g. Melesa Poole), alternate/cell phone number Sort order: Patient First Name – ascending Patient Last Name – ascending |
|
3. Display a list of all patients who do not have an email address. |
Patient First Name, followed by a space, followed by the patient’s last name. (e.g. Melesa Poole) Sort order: Patient First Name – ascending Patient Last Name – ascending |
|
4. Display a list of all patients who live in zipcode 24551. |
Patient Last Name, Address1, Address2, City, State, Zip Sort order: Patient Last Name – descending |
|
5. Display a list of all physicians whose specialty is Internal Medicine or Orthopedics |
Physician First Name, space, last name (call this column Physician), Specialty Sort order: Physician First Name – ascending Physician Last Name – descending |
|
6. Display a list of all physicians, their specialties, and their practices |
Physician Last Name, Specialty, Practice Sort order: Physician Specialty – ascending Physician Last Name – ascending Practice – ascending |
|
7. Display a list of all physicians whose practices are in Lynchburg |
Physician Last Name, Practice Name, Address, City, State, Zipcode, Phone Sort order: Zipcode – ascending Practice Name – descending Physician Last Name – ascending |
|
8. Display the number of physicians in each specialty |
Specialty, number of physicians in each specialty Sort order: Specialty |
|
9. Display the number of physicians in each practice, broken out by specialty |
Practice, Specialty, number of physicians in each Sort order: Practice – ascending Specialty -- ascending |
|
10. Display the list of specialties that have no physicians assigned to them. |
Specialty Sort order: Specialty – ascending |
2.
Select FirstName,LastName,Phone-Alternate from Patients order by FirstName,LastName;
3.
Select FirstName,LastName from Patients where Email IS NULL order by Email;
4.
Select Lastname,Address_Line1,Address_Line2, ZipCode from Patients where ZipCode = 24551 order by LastName desc;
5.
Select FirstName,LastName as Physician,SpecialityName from Physicians inner join PhysicianSpecialities on Physicians.SpecialityID = PhysicianSpecialities.SpecialityID order by FirstName,LastName desc;
6.
Select LastName,SpecialityName , PracticeName from Physicians inner join PhysicianSpecialities on Physicians.SpecialityID = PhysicianSpecialities.SpecialityID inner join PhysicianPractices on Physicians.PracticeID = PhysicianPractices.PracticeID order by LastName , PracticeName;
7.
Select LastName , PracticeName, Address_Line1,Address_Line2, ZipCode,Phone from Physicians inner join PhysicianPractices on Physicians.PracticeID = PhysicianPractices.PracticeID order by ZipCode,PracticeName desc, LastName ;
8.
Select SpecialityName, count(PhysicianID) from Physicians inner join PhysicianSpecialities on Physicians.SpecialityID = PhysicianSpecialities.SpecialityID group by SpecialityName order by SpecialityName;
9.
Select PracticeName, count(PhysicianID) from Physicians inner join PhysicianPractices on Physicians.PracticeID = PhysicianPractices.PracticeID group by PracticeName order by PracticeName;
10.
Select SpecialityName from Physicians , PhysicianSpecialities where Physicians.SpecialityID != PhysicianSpecialities.SpecialityID order by SpecialityName;
Do ask if any doubt. Please upvote.
Create a new database and execute the code below in SQL Server’s query window to create...
SQL Query Question: I have a database with the tables below, data has also been aded into these tables, I have 2 tasks: 1. Add a column to a relational table POSITIONS to store information about the total number of skills needed by each advertised position. A name of the column is up to you. Assume that no more than 9 skills are needed for each position. Next, use a single UPDATE statement to set the values in the new...
Write an SQL query to return the users who posted the most number of jokes on 1/1/2019. Database: create table User( userid varchar(30) not null, password varchar(30), firstname varchar(30), lastname varchar(50), email varchar(50), gender char(1), age integer, banned boolean, primary key(userid), unique(email)); create table MyFriends( userid varchar(30), friendid varchar(30), primary key(userid,friendid), foreign key(userid) references User, foreign key(friendid) references User(userid)); Create table Jokes( Jokeid integer, title varchar(100), description varchar(255), authorid varchar(30) not null, primary key(jokeid), posttime Datetime, foreign key(authorid) references User(userid));...
Display all customers. If a customer has placed any orders, also
display the highest.....
Tables:
CREATE TABLE Sales.Customers
(
CustomerId
INT
NOT NULL
IDENTITY,
CustomerName
NVARCHAR(50)
NOT NULL,
StreetAddress NVARCHAR(50) NULL,
City
NVARCHAR(20)
NULL,
[State]
NVARCHAR(20)
NULL,
PostalCode
NVARCHAR(10)
NULL,
Country
NVARCHAR(20)
NULL,
Contact
NVARCHAR(50)
NULL,
Email
NVARCHAR(50)
NULL,
CONSTRAINT PK_Customers PRIMARY KEY(CustomerId)
);
CREATE TABLE HR.Employees
(
EmployeeId
INT
NOT NULL
IDENTITY,
FirstName
NVARCHAR(50) NOT
NULL,
LastName
NVARCHAR(50)
NOT NULL,
BirthDate DATE
NOT NULL,
HireDate
DATE
NOT NULL,
HomeAddress...
The following SQL DDL script creates a database for a social network application. create table userProfile( id char(10) primary key, firstName varchar(20), lastName varchar(20), dob date, email varchar(30) ); create table foaf( userid char(10), friendID char(10), timeEstablished date, constraint pk primary key(userid, friendID), constraint fk1 foreign key(userid) references userProfile(id), constraint fk2 foreign key(friendID) references userProfile(id) ); create table activity( actID char(20) primary key, topic varchar(20), description varchar(100), location varchar(20), ActivityDate date, hostUser char(10), foreign key(hostUser) references userProfile(id) ); create table...
CREATE TABLE Gender ( gender CHAR(1), description VARCHAR(10), PRIMARY KEY (gender) ); CREATE TABLE People ( ID INT, name VARCHAR(50), gender CHAR(1), height FLOAT, PRIMARY KEY (ID), FOREIGN KEY (gender) REFERENCES Gender (gender) ); CREATE TABLE Sports ( ID INT, name VARCHAR(50), record FLOAT, PRIMARY KEY (ID), UNIQUE (name) ); CREATE TABLE Competitions ( ID INT, place VARCHAR(50), held DATE, PRIMARY KEY (ID) ); CREATE TABLE Results ( peopleID INT NOT NULL, competitionID INT NOT NULL, sportID INT NOT NULL,...
Given the mySQL tables created below... Create a mySQL solution to return the itemIDs of items posted by user X, such that all the reviews are “Excellent” or “Good” for these items CREATE TABLE Users ( userId varchar (30) NOT NULL, pass varchar (30), fname varchar (50), lname varchar (50), email varchar (50), gender char(1), age integer, banned boolean, PRIMARY KEY (userId), UNIQUE(email)) CREATE TABLE FavSellers ( userId...
Define an SQL view JokesNum that gives the number of jokes each user posts on each day. Database: create table User( userid varchar(30) not null, password varchar(30), firstname varchar(30), lastname varchar(50), email varchar(50), gender char(1), age integer, banned boolean, primary key(userid), unique(email)); create table MyFriends( userid varchar(30), friendid varchar(30), primary key(userid,friendid), foreign key(userid) references User, foreign key(friendid) references User(userid)); Create table Jokes( Jokeid integer, title varchar(100), description varchar(255), authorid varchar(30) not null, primary key(jokeid), posttime Datetime, foreign key(authorid) references User(userid));...
Create a stored procedure that allows a user to select a bat’s manufacturer and (optionally) serial number using a stored procedure. The output should display all of the players who use the bat’s manufacturer. If the serial number is also provided, only display the players who use that bat’s manufacturer and serial number. Make sure you use a CREATE PROCEDURE call and insert this procedure into the existing database. Submit a document that includes: 1. Commented code for the stored...
/* I am executing following SQL statement for the below code but I am getting error. Pls, upload screenshot after running it. SQL Statement: SELECT OfferNo, CourseNo FROM Offering WHERE OfferTerm = 'Sum' AND OfferYear = 2012 AND FacSSN IS NULL; */ CREATE TABLE STUDENT( StdSSN INT NOT NULL PRIMARY KEY, StdFName VARCHAR2(50), StdLName VARCHAR2(50), StdCity VARCHAR2(50), StdState VARCHAR2(2), StdZip VARCHAR2(10), StdMajor VARCHAR2(15), StdYear VARCHAR2(20) ); CREATE TABLE FACULTY( FacSSN INTEGER NOT NULL PRIMARY KEY, FacFName VARCHAR(50), FacLName VARCHAR(50), FacCity...
Given the following table structure, write the SQL code to display all the first and last names of the individuals that have a last name that begins with the letter 'M! CREATE TABLE Persons Personi int LastName varchar(80). FirstName varchar(80). Address varchar(125). State char(2) Given the following table structure, write the SQL code to display all the first and last names of the individuals that have a last name that does not contain the letter 'S: CREATE TABLE Persons PersonlDint,...