in Databases edited by
2,287 views
0 votes
0 votes

Create table Employee(Emp_id numeric not null, Name varchar(20) , dept_name varchar(20), Salary numeric unique(Emp_id,Name));


What will be the result of the query?
insert into Employee values(1002, 'Ross', 'CSE', 10000)
insert into Employee values(1006,'Ted','Finance', );
insert into Employee values(1002,'Rita','Sales',20000);



a) All statements executed
b) Error in create statement
c) Error in insert into Employee values(1006,'Ted','Finance', );
d) Error in insert into Employee values(1008,'Ross','Sales',20000);

in Databases edited by
by
2.3k views

1 comment

What is Unique here? Salary or (Emp_id,name)???
0
0

2 Answers

1 vote
1 vote
option b)  error in create statement as , (comma ) should be there before unique keyword else it is fine

option c) error will be there as last argument is missing
edited by

2 Comments

Sir, If single quotes are present (as in Edited version of  the question) what will be the answer?
0
0
i think comma will be there in question in create statement so option C will be ans
0
0
1 vote
1 vote
This question with some minor ambiguity:

If we talking about SQL server or something then 'Salary' should be unique and there is ','(comma) after it.
In that case Option-(D) is True because Salary can have Null value(only one) but it can't have multiple values.

If we talking about MySql then (Emp_id,Name) (combination)should be Unique and there should be ','(comma) before it.
In that case option-(A) is True.

Reference:
http://www.w3schools.com/sql/sql_unique.asp
http://sqlhints.com/2013/06/02/difference-between-primary-key-and-unique-key-in-sql-server/

Correct me if I'm wrong!

Related questions