Warning: Creating default object from empty value in /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4991

Warning: Creating default object from empty value in /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4993
Question 28: Which of the statements below are true? – MySQL Question of the Day

Skip to content

By urs in mysql questions

 
Observe the following scenario:
 

create table pktest1(id int);
create table pktest2 like pktest1;
insert into pktest1 values (1),(1),(2),(2),(3),(3),(1);
insert into pktest2 select * from pktest1;

 

alter table pktest1 add primary key(id);
alter ignore table pktest2 add primary key(id);

 
Which of the statements below are true?
 
(Find all correct answers)
 

a) The ALTER on pktest1 will fail.
b) The ALTER on pktest2 will fail.
c) The ALTER on pktest2 will remove duplicates.
d) The ALTER on pktest1 will remove duplicates.

 
[ Tables and Indexes (15%) - Altering Tables ]
 

Tags: , ,

Comment Feed

One Response


  1.  
    Answers:
     
    a c
     
    In general, you can only add a constraint to a table, if the existing data does not violate the constraint. However, with the IGNORE option, any duplicates will be removed while adding primary or unique keys (very useful!).
     

You must be logged in to post a comment.