question

KOSdbms avatar image
0 Votes"
KOSdbms Suspended asked ErlandSommarskog commented

PRIMARY KEY VS FOREIGN KEYS SSMS (2019) EXPRESS


I have three tables at SQL SERVER 2019 described below:

Table DEPARTMENTS : Columns DeptID , DeptName example FINANCE, IT .

Table EMPLOYEE : Columns : employeeID , SupervisorID .

Table SUPERVISOR : Columns : FirstName, LastName, SupervisorID, DeptID .

HOW TO EXECUTE ON QUERY in SQL SYNTAX OF PRIMARY KEYS AND FOREIGN KEYS FOR THESE THREE TABLES???

THANK YOU DEAREST FRIENDS . YOUNG KOSOVAR CITIZEN FROM KOSOVO ..

sql-server-transact-sql
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

What are the primary keys and foreign keys of the three tables? And what query do you want to execute?

1 Vote 1 ·

Query to execute and for add three tables to add primary key and foreign syntax example ???

0 Votes 0 ·

What are you doing with these three tables? You mentioned that you need to use primary and foreign keys, so we need to know which columns their primary and foreign keys are. The primary key and foreign key are one or more columns of the table.

0 Votes 0 ·

Good day and welcome tot he QnA forum @KOSdbms ,

I have three tables

Where are the tables?!?

Your message include only a poor description of columns names.

Please provide queries to create the tables including any index, constraints, and relations. In addition please provide queries to INSERT some sample data for the discussion, and please describe your expected result SET according to the sample data which you inserted using the sample queries. Thanks

This information will help us to preproduce the scenario

0 Votes 0 ·

1 Answer

ErlandSommarskog avatar image
1 Vote"
ErlandSommarskog answered ErlandSommarskog commented

Some sample statements to get you started:

ALTER TABLE Department ADD CONSTRAINT pk_Department PRIMARY KEY(DeptId)
ALTER TABLE Supervisor ADD 
   CONSTRAINT fk_Supervisor_Department 
   FOREIGN KEY (DeptID) REFERENCES (DeptID)

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

thank you very much dearest bro FROM Kosova.

Do I need to add Employees with ALTER TABLE Or not?

0 Votes 0 ·

Since I don't know your requirements I cannot say what you need. But it seems reasonable that Employees would have an FK to Supervisor. And a primary key. As I said, the above is only a sample. The rest is left as an exercise to the reader.

0 Votes 0 ·