Question

In: Computer Science

Create a table in SQL with foreign key reference: 1.Create the three tables without any columns...

Create a table in SQL with foreign key reference:

1.Create the three tables without any columns

2.Alter the tables to add the columns

3.Alter the tables to create the primary and foreign keys

Solutions

Expert Solution

SQL statements-->

1->

create 3 empty tables ->

CREATE TABLE TABLE1("\0");

CREATE TABLE TABLE2("\0");

CREATE TABLE TABLE3("\0");

These 3 statements will create 3 table with 0 columns and records.

CREATE is used to create

TABLE is used to give table name

TABLE1 is table name

\0 is used to set 0 columns.

2-->

  to add columns to a table -->

ALTER TABLE TABLE1 ADD FirstName varchar(55);

ALTER TABLE Table1 ADD ID integer(5);

ALTER TABLE Table1 ADD orderID integer(5);

now for table 2 -

ALTER TABLE TABLE2 ADD FirstName varchar(55);

ALTER TABLE Table2 ADD ID integer(5);

ALTER TABLE Table2 ADD orderID integer(5);

same for table 3

3 -->

now we add primary and foreign key -->

ALTER TABLE TABLE1 ADD CONSTRAINT PK_Person PRIMARY KEY (ID);

ALTER TABLE TABLE2 ADD CONSTRAINT PK_Person PRIMARY KEY (orderID);

ALTER TABLE TABLE1 ADD FOREIGN KEY (orderID) REFERENCES TABLE2(orderID);

like this we can add primary and foreign keys

  

  

  


Related Solutions

Create table, create primary and foreign key constraints. Create index on the table to satisfy a...
Create table, create primary and foreign key constraints. Create index on the table to satisfy a query with aggregate functions.
1. Use SQL to create a polyinstantiated table including a primary key and a unique constraint...
1. Use SQL to create a polyinstantiated table including a primary key and a unique constraint 2.Use SQL to insert multiple records for each security classification with the same ID. You must have 4 classifications. 3.Use SQL to create 4 schemas, one for each security classification 4.Use SQL to create a view in each schema that restricts the records to those belonging to a particular security classification and restricts the columns to only those columns that have relevant data. 5.Select...
1. Write CREATE TABLE statements for the following tables (foreign keys are in italic and bold)....
1. Write CREATE TABLE statements for the following tables (foreign keys are in italic and bold). Make sure you have all needed constraints and appropriate datatypes for attributes: Student (stID, stName, dateOfBirth, advID, majorName, GPA) Advisor (advID, advName, specialty) 2.  Insert several records in each table.
Create a new SQL table in your phpMyAdmin account that collects the following fields (columns) -  (10...
Create a new SQL table in your phpMyAdmin account that collects the following fields (columns) -   1) The name of a medicine, sanitizer, or tip/trick for protecting yourself against transmission or fight the disease - STRING 2) The amount of money the item costs - NUMBER 3) The UPC code of the item - NUMBER 4) Manufacturing country of the item - STRING Connect to the SQL database with your HTML code, and make sure to show the results of...
1 – Create a webpage that contains a table with exactly three rows and two columns....
1 – Create a webpage that contains a table with exactly three rows and two columns. The first row will contain a table heading containing the name of a US National Park, that spans across all columns. Hint: use the colspan attribute inside the opening th tag Give the table heading an onmouseover that will change the text of the heading when it is moused over to read My Favorites Park! (Hint: use innerHTML). Use onmouseout to change it back....
1 – Create a webpage that contains a table with exactly three rows and two columns....
1 – Create a webpage that contains a table with exactly three rows and two columns. The first row will contain a table heading containing the name of a US National Park, that spans across all columns. Hint: use the colspan attribute inside the opening th tag Give the table heading an onmouseover that will change the text of the heading when it is moused over to read My Favorites Park! (Hint: use innerHTML). Use onmouseout to change it back....
SUBJECT: PROGRAMMING IN SQL 1. Create a view named vDepartmentInstructors that returns these columns: the DepartmentName...
SUBJECT: PROGRAMMING IN SQL 1. Create a view named vDepartmentInstructors that returns these columns: the DepartmentName column from the Departments table the LastName, FirstName, Status, and AnnualSalary columns from the Instructors table. 2. Write a SELECT statement that returns all the columns from the vDepartmentInstructors view that you created in question 1. Return one row for each fulltime instructor in the English department. 3. Write an UPDATE statement that updates the vDepartmentInstructors view you created in question 1 so it...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The first database table will contain the names of at least four movies. The second table will be a list of actors who appear in the movies. The third table will be an associative table that describes the relationship between the actors and their movies (which actors appear in which movies). Actors and movies have a “many-to-many relationship,” meaning an actor can be in multiple...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The first database table will contain the names of at least four movies. The second table will be a list of actors who appear in the movies. The third table will be an associative table that describes the relationship between the actors and their movies (which actors appear in which movies). Actors and movies have a “many-to-many relationship,” meaning an actor can be in multiple...
Tables: Create table Item(    &nbs... Bookmark Tables: Create table Item(                 ItemId           &nb
Tables: Create table Item(    &nbs... Bookmark Tables: Create table Item(                 ItemId                 char(5) constraint itmid_unique primary key,                 Decription           varchar2(30),                 Unitcost               number(7,2)); Create table Customer(                 custID                   char(5) constraint cid.unique primary key,                 custName          varchar2(20),                 address                                varchar2(50)); Create table Orderdata( orderID                char(5) constraint oid_uniq primary key,                 orderdate           date,                 shipdate              date,                 ItemId                  char(5) references Item.ItemId,                 No_of_items     number(4),                 Unitcost               number(7,2),                 Order_total        number(7,2),                 custID                   char(5) references customer.custID); Insert Into Item values(‘A123’,’Pencil’,2.5);...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT