Nihariya is responsible for managing a smart farming system that monitors various fields, crops, and field conditions. She needs to ensure that the data in these tables is accurate and meaningful.Write the DDL statements to create the following tables with the mentioned constraints to handle the data:symbol refers to the primary key NN refers to Not NULL Create the FIELD table to store information about the fields.Create the CROP table with a foreign key constraint named FK_FIELD_ID to reference the FIELD (FIELD_ID), ensuring each crop is associated with a specific field.Create the FIELD_CONDITION table with a foreign key constraint named FK_FIELD_CONDITION_FIELD_ID to reference the FIELD table's FIELD_ID column and a check constraint named CK_CONDITION_TYPE to ensure the CONDITION_TYPE column contains one of these four values: 'soil moisture', 'temperature', 'humidity', 'pH'.Note: The user must write only the query to create and alter the table. The query to display the description of the table is already given.Input format :No console inputOutput format :The output displays the successful table creation status and the structure of all three tablesRefer to the sample output.Sample test cases :Input 1 :Output 1 :Table FIELD created.Table CROP created.Table FIELD_CONDITION created. Name Null? Type _____________ ___________ ________________ FIELD_ID NOT NULL NUMBER FIELD_NAME NOT NULL VARCHAR2(100) LOCATION NOT NULL VARCHAR2(100) Name Null? Type ________________ ___________ ________________ CROP_ID NOT NULL NUMBER CROP_NAME NOT NULL VARCHAR2(100) PLANTING_DATE NOT NULL DATE FIELD_ID NOT NULL NUMBER Name Null? Type _________________ ___________ _______________ CONDITION_ID NOT NULL NUMBER FIELD_ID NOT NULL NUMBER CONDITION_TYPE NOT NULL VARCHAR2(50) VALUE NOT NULL NUMBER RECORDED_AT NOT NULL TIMESTAMP(6) 0 rows selected. Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.
Question
Nihariya is responsible for managing a smart farming system that monitors various fields, crops, and field conditions. She needs to ensure that the data in these tables is accurate and meaningful.Write the DDL statements to create the following tables with the mentioned constraints to handle the data:symbol refers to the primary key NN refers to Not NULL Create the FIELD table to store information about the fields.Create the CROP table with a foreign key constraint named FK_FIELD_ID to reference the FIELD (FIELD_ID), ensuring each crop is associated with a specific field.Create the FIELD_CONDITION table with a foreign key constraint named FK_FIELD_CONDITION_FIELD_ID to reference the FIELD table's FIELD_ID column and a check constraint named CK_CONDITION_TYPE to ensure the CONDITION_TYPE column contains one of these four values: 'soil moisture', 'temperature', 'humidity', 'pH'.Note: The user must write only the query to create and alter the table. The query to display the description of the table is already given.Input format :No console inputOutput format :The output displays the successful table creation status and the structure of all three tablesRefer to the sample output.Sample test cases :Input 1 :Output 1 :Table FIELD created.Table CROP created.Table FIELD_CONDITION created. Name Null? Type _____________ ___________ ________________ FIELD_ID NOT NULL NUMBER FIELD_NAME NOT NULL VARCHAR2(100) LOCATION NOT NULL VARCHAR2(100) Name Null? Type ________________ ___________ ________________ CROP_ID NOT NULL NUMBER CROP_NAME NOT NULL VARCHAR2(100) PLANTING_DATE NOT NULL DATE FIELD_ID NOT NULL NUMBER Name Null? Type _________________ ___________ _______________ CONDITION_ID NOT NULL NUMBER FIELD_ID NOT NULL NUMBER CONDITION_TYPE NOT NULL VARCHAR2(50) VALUE NOT NULL NUMBER RECORDED_AT NOT NULL TIMESTAMP(6) 0 rows selected. Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.
Solution
Here are the DDL statements to create the tables as per the requirements:
CREATE TABLE FIELD (
FIELD_ID NUMBER NOT NULL,
FIELD_NAME VARCHAR2(100) NOT NULL,
LOCATION VARCHAR2(100) NOT NULL,
CONSTRAINT PK_FIELD PRIMARY KEY (FIELD_ID)
);
CREATE TABLE CROP (
CROP_ID NUMBER NOT NULL,
CROP_NAME VARCHAR2(100) NOT NULL,
PLANTING_DATE DATE NOT NULL,
FIELD_ID NUMBER NOT NULL,
CONSTRAINT PK_CROP PRIMARY KEY (CROP_ID),
CONSTRAINT FK_FIELD_ID FOREIGN KEY (FIELD_ID) REFERENCES FIELD(FIELD_ID)
);
CREATE TABLE FIELD_CONDITION (
CONDITION_ID NUMBER NOT NULL,
FIELD_ID NUMBER NOT NULL,
CONDITION_TYPE VARCHAR2(50) NOT NULL,
VALUE NUMBER NOT NULL,
RECORDED_AT TIMESTAMP(6) NOT NULL,
CONSTRAINT PK_FIELD_CONDITION PRIMARY KEY (CONDITION_ID),
CONSTRAINT FK_FIELD_CONDITION_FIELD_ID FOREIGN KEY (FIELD_ID) REFERENCES FIELD(FIELD_ID),
CONSTRAINT CK_CONDITION_TYPE CHECK (CONDITION_TYPE IN ('soil moisture', 'temperature', 'humidity', 'pH'))
);
These statements will create the FIELD, CROP, and FIELD_CONDITION tables with the specified constraints. The FIELD table has a primary key FIELD_ID. The CROP table has a foreign key FIELD_ID referencing the FIELD table's FIELD_ID. The FIELD_CONDITION table has a foreign key FIELD_ID referencing the FIELD table's FIELD_ID and a check constraint on the CONDITION_TYPE column to ensure it contains one of the four specified values.
Similar Questions
Dia is responsible for managing a pharmaceutical production and distribution system. This system tracks information about drugs, production batches, and shipments. She needs to ensure that the data across these tables is accurate and meaningful.Write the DDL statements to create the following tables with the specified constraints:symbol refers to the primary key NN refers to Not NULL Create the DRUG table to store information about different drugs.Create the BATCH table with a foreign key constraint named FK_DRUG_ID to reference the DRUG table's DRUG_ID column, ensuring each batch is associated with a specific drug. Include a check constraint named CK_QUANTITY to ensure the QUANTITY column has a positive value.Create the SHIPMENT table with a foreign key constraint named FK_BATCH_ID to reference the BATCH table's BATCH_ID column, ensuring each shipment is linked to a specific production batch. Include a check constraint named CK_QUANTITY_SHIPPED to ensure the QUANTITY_SHIPPED column has a positive value.Note: The user must write only the query to create and alter the table. The query to display the description of the table is already given.Input format :No console inputOutput format :The output displays the successful table creation status and the structure of all three tablesRefer to the sample output.Sample test cases :Input 1 :Output 1 :Table DRUG created.Table BATCH created.Table SHIPMENT created. Name Null? Type ____________________ ___________ ________________ DRUG_ID NOT NULL NUMBER DRUG_NAME NOT NULL VARCHAR2(100) ACTIVE_INGREDIENT NOT NULL VARCHAR2(100) CATEGORY NOT NULL VARCHAR2(50) Name Null? Type __________________ ___________ _______________ BATCH_ID NOT NULL NUMBER DRUG_ID NOT NULL NUMBER BATCH_NUMBER NOT NULL VARCHAR2(50) PRODUCTION_DATE NOT NULL DATE QUANTITY NOT NULL NUMBER Name Null? Type ___________________ ___________ ________________ SHIPMENT_ID NOT NULL NUMBER BATCH_ID NOT NULL NUMBER SHIPMENT_DATE NOT NULL DATE DESTINATION NOT NULL VARCHAR2(255) QUANTITY_SHIPPED NOT NULL NUMBER TABLE_NAME SEARCH_CONDITION STATUS _____________ __________________________________ __________ BATCH QUANTITY > 0 ENABLED BATCH "DRUG_ID" IS NOT NULL ENABLED BATCH "BATCH_NUMBER" IS NOT NULL ENABLED BATCH "PRODUCTION_DATE" IS NOT NULL ENABLED BATCH "QUANTITY" IS NOT NULL ENABLED DRUG "DRUG_NAME" IS NOT NULL ENABLED DRUG "ACTIVE_INGREDIENT" IS NOT NULL ENABLED DRUG "CATEGORY" IS NOT NULL ENABLED SHIPMENT QUANTITY_SHIPPED > 0 ENABLED SHIPMENT "BATCH_ID" IS NOT NULL ENABLED SHIPMENT "SHIPMENT_DATE" IS NOT NULL ENABLED SHIPMENT "DESTINATION" IS NOT NULL ENABLED SHIPMENT "QUANTITY_SHIPPED" IS NOT NULL ENABLED 13 rows selected.
David is developing a recipe management system for a cooking app. The system tracks users, their recipes, and ingredients. Write the DDL statements to create the following tables with the mentioned constraints to handle the data: symbol refers to the primary key NN refers to Not NULLCreate a USERS table with a unique constraint named Users_Email_uk on the Email column.Create an INGREDIENTS table with a unique constraint named unique_ingredient_id on the IngredientID column.Remove the unique constraint named Users_Email_uk from the USERS table as it is no longer required.Add a new unique constraint named Recipes_RecipeName_uk on the RecipeName column in the RECIPES table.Note: The user must write only the query to create and alter the table. The query to display the description of the table is already given.Input format :No console inputOutput format :The output displays the successful table creation status and the structure of all three tablesRefer to the sample output.Sample test cases :Input 1 :Output 1 :Table USERS created.Table RECIPES created.Table INGREDIENTS created.Table USERS altered.Table RECIPES altered. Name Null? Type ___________ ________ ________________ USERID NUMBER USERNAME VARCHAR2(100) EMAIL VARCHAR2(100) Name Null? Type _____________ ___________ ________________ RECIPEID NOT NULL NUMBER USERID NOT NULL NUMBER RECIPENAME VARCHAR2(100) Name Null? Type _________________ ___________ ________________ INGREDIENTID NOT NULL NUMBER RECIPEID NOT NULL NUMBER INGREDIENTNAME VARCHAR2(100) TABLE_NAME CONSTRAINT_NAME STATUS ______________ ________________________ __________ INGREDIENTS UNIQUE_INGREDIENT_ID ENABLED RECIPES RECIPES_RECIPENAME_UK ENABLED 2 rows selected.
Mia is developing a health monitoring app to track user activities and vital signs. The app needs to handle three main types of data: OWNERS, PROPERTIES, and TENANTSWrite the DDL statements to create the following tables with the mentioned constraints to handle the data: The OWNERS table has a named primary key constraint pk_owners for OwnerID.The PROPERTIES table has a named primary key constraint pk_properties for VehicleID and a named foreign key constraint fk_owner that references OwnerID in OWNERS table.The TENANTS table has a named primary key constraint pk_tenants forTenantID.symbol refers to the primary key NN refers to Not NULLWhile creating a table PROPERTIES include a foreign key named fk_owner for the column OwnerID with the references of OWNERS table (OwnerID)After creating the tables, Mia needs to:Add the foreign key fk_property_id to the TENANTS table with the references of the PROPERTIES table(propertyID).Drop the foreign key fk_owner from the PROPERTIES table as it is no longer required.Note: The user must write only the query to create and alter the table. The query to display the description of the table is already given.Input format :No console inputOutput format :The output displays the successful table creation status and the structure of all three tablesRefer to the sample output.Sample test cases :Input 1 :Output 1 :Table OWNERS created.Table PROPERTIES created.Table TENANTS created.Table TENANTS altered.Table PROPERTIES altered. Name Null? Type ______________ ___________ ________________ OWNERID NOT NULL NUMBER NAME VARCHAR2(100) CONTACTINFO VARCHAR2(100) Name Null? Type _____________ ___________ ________________ PROPERTYID NOT NULL NUMBER OWNERID NOT NULL NUMBER ADDRESS VARCHAR2(255) Name Null? Type _____________ ___________ ________________ TENANTID NOT NULL NUMBER PROPERTYID NOT NULL NUMBER TENANTNAME VARCHAR2(100) TABLE_NAME COLUMN_NAME POSITION STATUS _____________ ______________ ___________ __________ OWNERS OWNERID 1 ENABLED 1 row selected.
Archie is developing a library management system to manage books, authors, and borrowers. The system needs to handle three main types of data: BOOKS, AUTHORS, and BORROWERS.Write the DDL statements to create the following tables with the mentioned constraints to handle the data: symbol refers to the primary key NN refers to Not NULL After creating the tables, Archie needs to:Alter the BOOKS table to change the primary key to Title to ensure each book is uniquely identified by its title.Drop the primary key from the BORROWERS table as it is no longer requiredAlter the AUTHORS table to change the Nationality to NULL Note: The user must write only the query to create and alter the table. The query to display the description of the table is already given.Input format :No console inputOutput format :The output displays the successful table creation status and the structure of all three tablesRefer to the sample output.Sample test cases :Input 1 :Output 1 :Table BOOKS created.Table AUTHORS created.Table BORROWERS created.Table BOOKS altered.Table BOOKS altered.Table BORROWERS altered.Table AUTHORS altered. Name Null? Type __________________ ___________ ________________ BOOKID NOT NULL NUMBER TITLE NOT NULL VARCHAR2(200) AUTHORID NOT NULL NUMBER PUBLICATIONYEAR NOT NULL NUMBER Name Null? Type ______________ ___________ ________________ AUTHORID NOT NULL NUMBER NAME NOT NULL VARCHAR2(100) NATIONALITY VARCHAR2(100) Name Null? Type _________________ ___________ ________________ BORROWERID NOT NULL NUMBER NAME NOT NULL VARCHAR2(100) MEMBERSHIPDATE NOT NULL DATE TABLE_NAME COLUMN_NAME POSITION STATUS _____________ ______________ ___________ __________ BOOKS TITLE 1 ENABLED 1 row selected. Note :
Alexander is developing a ride-sharing application to track drivers, vehicles, and trips. The system needs to handle three main types of data: DRIVERS, VEHICLES, and TRIPS. Write the DDL statements to create the following tables with the mentioned constraints to handle the data: The DRIVERS table has a named primary key constraint pk_driver.The VEHICLES table has a named primary key constraint pk_vehicle for VehicleID and a named foreign key constraint fk_driver for DriverID.The TRIPS table has a named primary key constraint pk_trip for TripID and a named foreign key constraint fk_vehicle for VehicleID.symbol refers to the primary key NN refers to Not NULLAlexander ensures the following constraints are altered:Remove the foreign key constraint named fk_driver from the VEHICLES table.Note: The user must write only the query to create and alter the table. The query to display the description of the table is already given.Input format :No console inputOutput format :The output displays the successful table creation status, the structure of all three tables, and the existing foreign key constraint details.Refer to the sample output.Sample test cases :Input 1 :Output 1 :Table DRIVERS created.Table VEHICLES created.Table TRIPS created.Table VEHICLES altered. Name Null? Type ________________ ___________ ________________ DRIVERID NOT NULL NUMBER NAME NOT NULL VARCHAR2(100) LICENSENUMBER NOT NULL VARCHAR2(20) Name Null? Type ____________ ___________ _______________ VEHICLEID NOT NULL NUMBER DRIVERID NOT NULL NUMBER MAKE NOT NULL VARCHAR2(50) MODEL NOT NULL VARCHAR2(50) Name Null? Type ____________ ___________ _________ TRIPID NOT NULL NUMBER VEHICLEID NOT NULL NUMBER TRIPDATE NOT NULL DATE DISTANCE NOT NULL NUMBER TABLE_NAME FOREIGN_KEY_NAME FOREIGN_KEY_COLUMN REFERENCED_CONSTRAINT_NAME REFERENCED_TABLE_NAME REFERENCED_COLUMN_NAME _____________ ___________________ _____________________ _____________________________ ________________________ _________________________ TRIPS FK_VEHICLE VEHICLEID PK_VEHICLE VEHICLES VEHICLEID 1 row selected. Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.