Select Database — SQL Technical Interview Questions & Answers

Select Database

Select Database

  • USE college; selects which database later statements talk to. It does not print the table. Think: open this cupboard, then look at registers inside.
  • In Workbench the schema you highlight is the same idea. In an app, the connection already names the database, so you often skip USE.
  • Check: SELECT DATABASE(); shows the one in use. NULL means you did not select any.
  • Trap: running SELECT * FROM students without USE, and MySQL says ‘No database selected’.
  • On the example next to this theory: Select Database — sELECT projects columns; WHERE filters; ORDER BY sorts.

Technical Interview Tip: USE college; then SELECT DATABASE();

Code Examples for Select Database

Select Database — sample query

CREATE TABLE employees (id INTEGER PRIMARY KEY, name TEXT, dept TEXT, salary INTEGER);
INSERT INTO employees VALUES
  (1, 'Asha', 'Eng', 70000),
  (2, 'Ravi', 'Eng', 65000),
  (3, 'Neha', 'HR', 50000);
SELECT name, salary FROM employees WHERE dept = 'Eng' ORDER BY salary DESC;

Select Database — sELECT projects columns; WHERE filters; ORDER BY sorts.

How to Explain Select Database to an Interviewer

How do you select a database?

USE college; SELECT DATABASE(); to verify