edited by
3,088 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);

edited by

2 Answers

1 votes
1 votes
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
1 votes
1 votes
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

1 votes
1 votes
3 answers
1
sh!va asked Feb 8, 2017
1,138 views
Consider the following relation instance myTablenum1num2100100100NULLNULL100NULLNULL Query 1:SELECT *FROM myTableWHERE num1 != NULL;Query 2:SELECT *FROM myTableWHERE num1...
0 votes
0 votes
2 answers
3
print asked Jan 21, 2022
455 views
Source Made Easy Test SeriresCan anyone please tell me the answer for this, with explaination. According to me it will give the customer who buy from atleast one store, b...
0 votes
0 votes
0 answers
4
shikharV asked Jan 4, 2016
388 views
I couldn't understand its solution. Please explain