-2

I have Two table

  1. customer table which has contained the information of the customer. But it has an account number we make a primary key of the account number.

  2. And now the second Table is Bill Table.I've use the account number of the customer table when we update some information about the Bill table then will update is automatically of the particular account number

so, please tell me how we can resolve this problem, and how we can use the foreign key of Bill table

Tasos K.
  • 7,979
  • 7
  • 39
  • 63

2 Answers2

0

I think what you are asking is how to update the Customer table at the same time when you are updating Bill table.

You can easily use a stored procedure to achieve this task. Within the stored procedure you can use transactions to make sure the 2nd update happens only if the first update is succeded. Otherwise, you can rollback.

Chameera Dulanga
  • 218
  • 5
  • 17
0

So imagine that this is your customer table:

CREATE TABLE customer (
    AccountNum int NOT NULL,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    PRIMARY KEY (AccountNum)
);

PRIMARY KEY (AccountNum) > so you have a primary key in that table. Kudos!

CREATE TABLE BillTable (
    OrderID int NOT NULL,
    OrderNumber int NOT NULL,
    AccountNum  int NOT NULL,
    PRIMARY KEY (OrderID),
    FOREIGN KEY (AccountNum) REFERENCES customer(AccountNum)
);

Now you linked customer and BillTable.

skmala
  • 1
  • 1