Question

INSPECTOR InsID InsName INSPECTING InsID (FK) BuildingID (FK) Date Last DateNext MANAGER ManagerID MFName MLName MBDate MSala

Column Name Data Type Managerid Mfname Mlname Msalary Mbdate Mbonus Mresbuildingid Mphone Char(4) Varchar(15) Varchar(15) Num

[IN SQL]

New to working in SQL and I need to make a database called HAFH. I am trying to create tables for the database with the information from the photo above but having issues.

I am looking for the syntax that successfully creates these tables, and references each other. I know each table has to be made in a specific order, and that is what I am struggling with.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

This demonstration is using SQL Server.

create database HAFH;

/*use database to create tables*/
use HAFH;

--1.Table Name :Inspector
create table Inspector(
InsID char(3) primary key,
InsName varchar(15)
);

NOTE :HERE NEED TO CREATE EITHER MANAGER TABLE OR BUILDING TABLE AND THE USING ALTER TABLE SYNTAX ADD THE FOREIGN KEY , HENCE MANAGER TABLE IS CREATED FIRST.

--2.Table Name :Manager
create table Manager(
ManagerID char(4) primary key,
MFName varchar(15),
MLName varchar(15),
MBDate date,
MSalary numeric(9,2),
MBonus numeric(9,2),
MResBuildingID char(3)
);

--3.Table Name :Building
create table Building(
BuildingID char(3) primary key,
BNoOfFloors int,
ManagerID char(4),
foreign key (ManagerID) references Manager(ManagerID)
);

alter table Manager add foreign key (MResBuildingID) references Building (BuildingID);

--4.Table Name :CORPCLIENT
create table CORPCLIENT(
CCID char(4) primary key,
CCName varchar(25),
CCIndustry varchar(25),
CCLocation varchar(25),
CCIDReferredBy char(4),
foreign key (CCIDReferredBy) references CORPCLIENT(CCID));

--5.Table Name :Apartment
create table Apartment(
AptNo char(5) primary key,
BuildingID char(3),
ANoOfBedrooms int,
CCID char(4),
foreign key (BuildingID) references Building(BuildingID),
foreign key (CCID) references CORPCLIENT(CCID)
);

--6.Table Name :Inspecting
create table Inspecting(
InsID char(3),
BuildingID char(3),
DateLast date,
DateNext date,
foreign key (BuildingID) references Building(BuildingID),
foreign key (InsID) references Inspector(InsID)
);

--7.Table Name :StaffMember
create table StaffMember(
SMemberID char(4) primary key,
SMemberName varchar(15)
);

--8.Table Name :Cleaning
create table Cleaning(
AptNo char(5),
BuildingID char(3),
SMemberID char(4),
foreign key (BuildingID) references Building(BuildingID),
foreign key (SMemberID) references StaffMember(SMemberID),
foreign key (AptNo) references Apartment(AptNo)
);

Add a comment
Know the answer?
Add Answer to:
[IN SQL] New to working in SQL and I need to make a database called HAFH....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • im currently working on an sql database homework for a fundamentals class but im not too...

    im currently working on an sql database homework for a fundamentals class but im not too sure if my results are alright and would like to compare results, the assignment is as follows: O4pk,fk evaluate de data models, the specifications and table contents: equipment_tb Assigned_Equipment_tb workers_tb pk serial_number int pk,fk serial number int pk worker_id int, Surrogate brand char(10) worker id int Lastname char(100) model char(15) assigned_date date Firstname char(50) processor char(15) department int processor_velocity number (3,2) email char(200) memory...

  • Help In Database: Next comes the data entry: Make up data for your database, or find...

    Help In Database: Next comes the data entry: Make up data for your database, or find real data. You can enter the data with INSERT statements, but it is much easier to use PhpAdmin. It has a form where you can type the data directly. Alternatively, you can use PhpAdmin to import CSV data (comma-separated values), which you can export from Excel. Include at least 3 rows in each of the entity relations, and as many rows as you need...

  • Question for SQL in MS SQL Server Management Studio (Please don't use where clause for Joins...

    Question for SQL in MS SQL Server Management Studio (Please don't use where clause for Joins use from clause) Need to Create a Query to display products purchased by customers in Germany that were not purchased by customers in the US. Customers PK Customer D CompanyName Contact Name Contact Title Address City State OrRegion PostalCode Country Phone char(5) varchar(40) varchar(30) varchar(30) varchar(60) varchar(15) varchar(15) varchar(10) varchar(15) varchar(24) varchar(24) Order Details Orders PK OrderID int FK CustomerlD char(5) FK Employeeld int...

  • Question for SQL in MS SQL Server Management Studio (Please don't use where clause for Joins...

    Question for SQL in MS SQL Server Management Studio (Please don't use where clause for Joins use from clause) Need to Create a Query because Northwind Traders wants to make sure that all orders are shipped within 10 days. Display any orders that were not shipped within 10 days. Include the OrderID, the OrderDate, and the number of days it took before the order was shipped. Customers PK Customer D CompanyName Contact Name Contact Title Address City State OrRegion PostalCode...

  • Question for SQL in MS SQL Server Management Studio (Please don't use where clause for Joins...

    Question for SQL in MS SQL Server Management Studio (Please don't use where clause for Joins use from clause) Need to Create a Query because Northwind Traders has decided to increase their retail prices. Write a query that shows the product name, the current price, and the new price. Make sure the new price is listed to 2 decimal points. Follow below guidelines on new retail price: a.         If the category is beverages or dairy products, increase the price by...

  • This script isn't working with SQL Server 2012, It keeps giving me an error of: There...

    This script isn't working with SQL Server 2012, It keeps giving me an error of: There is already an object named 'CustomerID' in the database. PLEASE HELP- What do I need to do????? CREATE TABLE [CustomerID] ( [CustomerID] int, [LastName] varchar(25), [FirstName] varchar(25), [PhoneNumber] varchar(10), [Address] varchar(75), [City] varchar(25), [Zip] int, [ServiceTicketID] int, PRIMARY KEY ([CustomerID]) ); CREATE INDEX [FK] ON [CustomerID] ([ServiceTicketID]); CREATE TABLE [ServiceTicket] ( [ServiceTicketID] int, [DateOfService] varchar(25), [Notes] varchar(100), [CustomerID] int, [PartsUsedID] int, PRIMARY KEY ([ServiceTicketID])...

  • In using a database created from this model, which of the following SQL queries would give...

    In using a database created from this model, which of the following SQL queries would give us a list of customers who have daily deposit transactions (deposit is a transaction type) totaling $10,000 or more across all of their accounts (i.e., this is a total across all accounts of a customer, not per account). Include in this list the Customer ID and name, and the dates and their respective daily total. SELECT c.cust_id, c.cust_name, DATE(t.tran_date), SUM(t.tran_amount) AS daily_total FROM Customers...

  • I need help with the following SQL query for a company database (script given below). The...

    I need help with the following SQL query for a company database (script given below). The name of the Department. The number of employees working in that department. The number of different projects controlled by this department. The name of the project controlled by this department that has the maximum number of employees of the company working on it. The number of the above project. The cumulative sum of the number of employees of the company working on the projects...

  • SQL Query Question: I have a database with the tables below, data has also been aded...

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT