Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (20.3k points)

Error SQL query:


-- Database: `work`


-- --------------------------------------------------------


-- Table structure for table `administrators`


CREATE TABLE IF NOT EXISTS `administrators` (

`user_id` varchar( 30 ) NOT NULL ,

`password` varchar( 30 ) NOT NULL ) ENGINE = InnoDB DEFAULT CHARSET = latin1;

MySQL said:

#1046 - No database selected

need some help here.

1 Answer

0 votes
by (40.7k points)
edited by

Before creating the table, you need to specify which database you are using in MYSQL. 

USE db_name;

Are you interested in learning SQL from the basics! Refer to this video on SQL provided by Intellipaat:

If in case the database does not exist, then you should create it as:


Which needs to be followed by:

USE db_name;

Browse Categories