Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Key on a table

$
0
0

hi

I need to design a table for holding employees. Each employee should have one manager and he is also an employee..

Create table EmpTable
(
Emp_Id int not null,
ename varchar(100),
mgr_id int unique  ,
PRIMary Key (emp_id),
foreign key (mgr_id)references EmpTable(emp_id)
)

so above table structure will allow me to insert on record with "mgr_id" as NULL..

i.e  it will allow me to insert following values

Emp_id, Ename,mgr_id

101,'XYX',Null

102,'ABC',101

103,'mno',101

but not

104,'PQR',NULL

How should i design my table to handle above situation

Case :

what if i need to insert more than one record( this is a situation where in i have more than one CEO for the company).


Sri


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>