This set of MySQL Questions and Answers for Freshers focuses on “MySQL Identifier Syntax and Naming Rules”.
1. Which of the following characters is illegal in naming an unquoted identifier in SQL?
Explanation: An identifier is used to refer to a database or its elements. These elements can be entire tables or attributes. The names of these identifiers follow some set of rules, so they have a set of legal characters.
2. In MySQL, identifier names can start with a digit.
Explanation: Identifiers are allowed to start with any legal character. So it may begin with a digit. The special characters in the identifier characters consist of the ‘_’ and ‘$’. The other characters are the alphanumeric characters.
3. How are identifiers quoted in MySQL?
a) single quotes
b) double quotes
d) can’t be quoted
Explanation: An identifier is quoted within the backtick characters ‘`’. This allows use of any character except a byte with value 0 or 255. Single quotes and double quotes are not allowed when quoting identifier names.
4. Which of the following is an illegal unquoted identifier name?
Explanation: In MySQL, the quoted and unquoted identifier names have differences in the level of restrictions imposed on them. An unquoted identifier name can’t have all digits since it would be impossible to distinguish it from an integer constant.
5. Which server mode value enables use of double quotes to wrap identifier names?
Explanation: In MySQL, use of double quotes is enabled when the server SQL mode ‘ANSI_QUOTES’ is set. The use of backticks is still allowed. For example, SELECT TABLE “my table” is a statement that is allowed.
6. Which server mode value disables use of built in function names as identifiers?
Explanation: The Server SQL mode value ‘IGNORE_FUNC’ is used to restrict the identifier naming conventions. When this is enabled, the names of built in functions can no longer be used as identifiers.
7. What is the maximum length for alias names in terms of characters?
Explanation: The identifiers in MySQL have a maximum length of 64 characters. However, the alias names for identifiers can have the number of characters up to 256. Aliases can also be quoted or unquoted.
8. What does a fully qualified table name consist of?
a) only the table name
b) only the database name
c) table name followed by database name
d) database name followed by table name
Explanation: MySQL identifiers use qualifiers. An element of a database has a fully qualified name. A database table in MySQL has the fully qualified name as the database name followed by the table name.
9. If no database has been selected, specifying a database qualifier is necessary.
Explanation: When no database has been selected, not specifying the database qualifier would be confusing. A table cannot be referred to if the database qualfier is absent, since it would be unclear as to which database it belongs to.
10. Which of the following statements is valid if ‘`sampledb`’ is a database and ‘`tbl`’ is a table in it?
a) SELECT * FROM `sampledb.member`
b) SELECT * FROM `sampledb`.`member`
c) SELECT * FROM `member`.`sampledb`
d) SELECT * FROM `member.sampledb`
Explanation: When quotes is being used to refer to a qualified name, the individual identifiers are quoted within the name separately. So, the database name `sampledb` and table name `tbl` are quoted separately.
Sanfoundry Global Education & Learning Series – MySQL Database.
To practice all areas of MySQL for Freshers, here is complete set of 1000+ Multiple Choice Questions and Answers.