In: Computer Science
- What SQL command would you use to make a table for products that includes three columns: a product’s ID, a product’s cost, and a product’s selling price?
- What SQL command would you use to make a table for telephone directory that contains a person’s full name, a person’s cellphone number, and a person’s home phone number?
- What SQL command would you use to make a table for an inventory of network equipment that includes the following: the device name, the physical location, the device’s primary IP address, and date of purchase?
1. To make Products Table: ID is numeric and cost ans selling price are float. ID is primary key because a product can be uniquely identified by ID.
CREATE TABLE Products (
ProductID int PRIMARY KEY,
Cost float,
SellingPrice float
);
2. To make Telephone Directory Table: Name is string whose length we have set to be maximum 50. Cell phone and home phone numbers would be int of length 10. Name is Primary Key because we use name to find a row in a telephone directory. (** You can change the lengths according to your choice**)
CREATE TABLE TelephoneDirectory (
Name varchar(50) PRIMARY KEY,
CellPhone int(10),
HomePhone int(10)
);
3. To make Inventory Table: Device Name is string whose length we have set to be maximum 50. Location and IPAddress would be string of length maximum 30. Purchase date is of data type:date. (** You can change the lengths according to your choice**)
CREATE TABLE Inventory (
Name varchar(50),
Location varchar(30),
IPAddress varchar(30),
PurchaseDate date
);