SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,494 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
how can i create fk relation with user in order table with these columns
AcceptedBy
RejectedBy
As Olaf suggests, it's straightforward:
CREATE TABLE users (id int NOT NULL,
username nvarchar(100) NOT NULL,
role nvarchar(100) NULL,
CONSTRAINT pk_users PRIMARY KEY (id)
)
CREATE TABLE orders (ordernumber int NOT NULL,
AcceptedBy int NULL,
RejectedBy int NULL,
CONSTRAINT pk_orders PRIMARY KEY (ordernumber),
CONSTRAINT fk_orders_users_AccepteBy
FOREIGN KEY (AcceptedBy) REFERENCES users(id),
CONSTRAINT fk_orders_users_RejecteddBy
FOREIGN KEY (RejectedBy) REFERENCES users(id)
)
go
DROP TABLE orders, users
Sure you can, why not?