I've to Define a table constraint on Dept that will ensure that all managers have age > 30. I'm a beginner in it so I do not want to use user defined function. Here I want a simple solution. which can apply my check in create table statement. I want to use check statement or assertion statement.
create table emp(eid int primary key,ename varchar(20),age int,salary real CHECK (salary >= 10000));
create table dept(did int primary key, buget real,managerid int foreign key (managerid) references emp check ((select eid from emp where age >30)));
and its giving the following error i do not know why
Msg 156, Level 15, State 1, Line 54
Incorrect syntax near the keyword 'select'.
Msg 102, Level 15, State 1, Line 54
Incorrect syntax near ')'.
I'm using Microsoft sql management studio 2014.
Tell me where I'm doing wrong. Thanks!