Question

CREATE TABLE vendor ( vendor_id int NOT NULL, vendor_name char(50) NOT NULL, contact_name char(50), CONSTRAINT vendors_pk...

CREATE TABLE vendor ( vendor_id int NOT NULL, vendor_name char(50) NOT NULL, contact_name char(50), CONSTRAINT vendors_pk PRIMARY KEY (vendor_id) );

What is the code to add the foreign key for this table? Can you please add the entire code with mine included. Thank you in advance.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
// vendor table -parent table

CREATE TABLE vendor ( vendor_id int NOT NULL, vendor_name char(50) NOT NULL, contact_name char(50), CONSTRAINT vendors_pk PRIMARY KEY (vendor_id) );

// dealer table -child table. 
CREATE TABLE dealer
( dealer_number int NOT NULL,
  dealer_name char(50) NOT NULL,
  dealer_id int,
  CONSTRAINT dealer_pk PRIMARY KEY (dealer_number),
  CONSTRAINT fk_vendor
    FOREIGN KEY (vendor_id)
    REFERENCES vendor(vendor_id)
);

// if you want to add foreign key to vendor table only, then

CREATE TABLE vendor ( vendor_id int NOT NULL, vendor_name char(50) NOT NULL, contact_name char(50), CONSTRAINT vendors_pk PRIMARY KEY (vendor_id),
CONSTRAINT fk_parent_table
    FOREIGN KEY (parent_table_primary_key)
    REFERENCES parentTable(parent_table_primary_key) );
Add a comment
Know the answer?
Add Answer to:
CREATE TABLE vendor ( vendor_id int NOT NULL, vendor_name char(50) NOT NULL, contact_name char(50), CONSTRAINT vendors_pk...
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
  • CREATE TABLE GLAccounts (    AccountNo INT,    AccountDescription VARCHAR(50),    --    CONSTRAINT GLAccounts_PK PRIMARY...

    CREATE TABLE GLAccounts (    AccountNo INT,    AccountDescription VARCHAR(50),    --    CONSTRAINT GLAccounts_PK PRIMARY KEY(AccountNo),    --    CONSTRAINT AccountDescription_NULL CHECK(AccountDescription IS NOT NULL),    --    CONSTRAINT AccountDescription_Zero_LEN CHECK(LEN(AccountDescription)>0) ); GO ----------------------------------------------------------------------------- CREATE TABLE Terms (    TermsID INT,    TermsDescription VARCHAR(50),    TermsDueDays SMALLINT,    --    CONSTRAINT PK_Terms PRIMARY KEY(TermsID),    --    CONSTRAINT TermsDescription_NULL    CHECK(TermsDescription IS NOT NULL),    CONSTRAINT TermsDueDays_NULL        CHECK(TermsDueDays IS NOT NULL),    --    CONSTRAINT TermsDescription_zero_LEN   ...

  • SQL CHECK CONSTRAINT AND TEST CASE... SQL Query Here are the tables: CREATE TABLE Movies(     movieID...

    SQL CHECK CONSTRAINT AND TEST CASE... SQL Query Here are the tables: CREATE TABLE Movies(     movieID INT,     name VARCHAR(30) NOT NULL,     year INT,     rating CHAR(1),     length INT,     totalEarned NUMERIC(7,2),     PRIMARY KEY(movieID),     UNIQUE(name, year) ); CREATE TABLE Showings(     theaterID INT,     showingDate DATE,     startTime TIME,     movieID INT,     priceCode CHAR(1),     PRIMARY KEY(theaterID, showingDate, startTime),     FOREIGN KEY(theaterID) REFERENCES Theaters,     FOREIGN KEY(movieID) REFERENCES Movies ); CREATE TABLE Tickets(     theaterID INT,     seatNum INT,     showingDate DATE,     startTime TIME,     customerID INT,     ticketPrice NUMERIC(4,2),     PRIMARY KEY(theaterID, seatNum, showingDate, startTime)...

  • CREATE TABLE Gender ( gender CHAR(1), description VARCHAR(10), PRIMARY KEY (gender) ); CREATE TABLE People (...

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

  • SQL I have a database CREATE TABLE vendor ( vid CHAR(2) NOT NULL, vname VARCHAR(25) NOT...

    SQL I have a database CREATE TABLE vendor ( vid CHAR(2) NOT NULL, vname VARCHAR(25) NOT NULL, PRIMARY KEY (vid) ); CREATE TABLE category ( catid CHAR(2) NOT NULL, catname VARCHAR(25) NOT NULL, PRIMARY KEY (catid) ); CREATE TABLE product ( pid CHAR(3) NOT NULL, pname VARCHAR(25) NOT NULL, price NUMERIC (7,2) NOT NULL, vid CHAR(2) NOT NULL, categoryid CHAR(2) NOT NULL, PRIMARY KEY (pid)); CREATE TABLE region ( rid CHAR NOT NULL, rname VARCHAR(25) NOT NULL, PRIMARY KEY (rid)...

  • Utilize the JigSaw SQL file below to create a Star Schema diagram. Remember, to create a...

    Utilize the JigSaw SQL file below to create a Star Schema diagram. Remember, to create a Star Schema from a normalized data model, you will need to denormalize the data model into fact and dimension tables. The diagram should contain all of the facts and dimension tables necessary to integrate the JigSaw operational database into a data warehouse. Write a brief paper describing the challenges you experienced in completing this assignment. -- CREATE DATABASE js; CREATE TABLE buy_methods ( buy_code...

  • MICROSOFT SQL SERVER - Create the following views 1.List the employee assigned to the most projects...

    MICROSOFT SQL SERVER - Create the following views 1.List the employee assigned to the most projects 2.List the project with the most hours SCRIPT TO BUILD DATABASE create table department ( dept_ID int not null , dept_name char(50) NOT NULL, manager_ID int not null, manager_start_date date not null, constraint Dept_PK primary key (dept_ID), constraint D_Name_AK unique (dept_name) ); insert into department values(1,'abc',1,'2019-01-08'); insert into department values(2,'abc2',2,'2019-01-08'); insert into department values(3,'abc3',2,'2019-01-08'); insert into department values(4,'abc4',2,'2019-01-08'); /*project table done*/ create table project...

  • Hello, Does anyone have any input on how to fragment this table in visual studio? CREATE...

    Hello, Does anyone have any input on how to fragment this table in visual studio? CREATE TABLE [dbo].[Stock] ( [itemNo] INT NOT NULL , [store] VARCHAR(50) NOT NULL, [qtyOnHand] INT NULL, [qtyHand] INT NULL, [qtyOnOrder] INT NULL, [reorderPoint] INT NULL, CONSTRAINT [FK_Stock_Item] FOREIGN KEY ([itemNo]) REFERENCES [Item]([itemNo]), CONSTRAINT [FK_Stock_Store] FOREIGN KEY ([store]) REFERENCES [Store]([storeName]), CONSTRAINT [PK_Stock] PRIMARY KEY ([itemNo], [store]), The other tables are: CREATE TABLE [dbo].[Item] ( [itemNo] INT NOT NULL PRIMARY KEY, [itemName] VARCHAR(50) NULL, [supplier] VARCHAR(50) NULL,...

  • Write a select statement that returns the vendorname and paymentsum of each vendor, where paymentsum is...

    Write a select statement that returns the vendorname and paymentsum of each vendor, where paymentsum is the sum of the paymentotal column. Return only the top ten vendors who have been paid the most and the number of invoices is >5. CREATE TABLE InvoiceArchive InvoiceID int NOT NULL, VendorID int NOT NULL InvoiceNumber varchar(50) NOT NULL, InvoiceDate smalldatetime NOT NULL, Invoice Total money NOT NULL, Payment Total money NOT NULL, CreditTotal money NOT NULL, TermsID int NOT NULL, InvoiceDueDate smalldatetime...

  • -- Schema definition create table Customer (     cid   smallint not null,     name varchar(20),    ...

    -- Schema definition create table Customer (     cid   smallint not null,     name varchar(20),     city varchar(15),     constraint customer_pk         primary key (cid) ); create table Club (     club varchar(15) not null,     desc varchar(50),     constraint club_pk         primary key (club) ); create table Member (     club varchar(15) not null,     cid   smallint     not null,     constraint member_pk         primary key (club, cid),     constraint mem_fk_club         foreign key (club) references Club,     constraint mem_fk_cust...

  • WRITING POSTGRESQL QUERIES RELATIONS: CREATE TABLE Movies(    movieID INT,    year INT UNIQUE,    rating...

    WRITING POSTGRESQL QUERIES RELATIONS: CREATE TABLE Movies(    movieID INT,    year INT UNIQUE,    rating CHAR(1),    length INT,    totalEarned NUMERIC(7,2),    PRIMARY KEY(movieID) ); CREATE TABLE Theaters(    theaterID INT,    address VARCHAR(40) UNIQUE,    numSeats INT NOT NULL,    PRIMARY KEY(theaterID) ); CREATE TABLE TheaterSeats(    theaterID INT,    seatNum INT,    brokenSeat BOOLEAN NOT NULL,    PRIMARY KEY(theaterID, seatNum),    FOREIGN KEY(theaterID) REFERENCES Theaters ); CREATE TABLE Showings(    theaterID INT,    showingDate DATE,   ...

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