Last answered:

27 Nov 2023

Posted on:

11 Nov 2023

0

General Question About a Syntax Requirement

Is there a guideline that is good to know or follow when considering the use of parenthesis in SQL syntax? 

It appears to me there is no rhyme or reason behind their use other than it's just the way it is. For example, why do we use them here:


ALTER TABLE Customers
ADD UNIQUE KEY (email_address);


and not here:


ALTER TABLE Customers
DROP INDEX email_address;



Thank you for your time

1 answers ( 0 marked as helpful)
Instructor
Posted on:

27 Nov 2023

0

Hi Andrew!
Thanks for reaching out.


In SQL, parentheses are used to group elements or specify a list of items. In the ALTER TABLE... ADD UNIQUE KEY (email_address) statement, parentheses are used to list the columns included in the unique key, accommodating the possibility of multiple columns. In the ALTER TABLE... DROP INDEX email_address statement, parentheses are not needed because it specifies a single index name without needing to list multiple elements.


Hope this helps.
Best,
Tsvetelin

Submit an answer