Reputation: 167
How to find out SQL DB is present or not if not present then create a new Database and if database is present then print database is connected successfully using nodejs
I know how to connect database and create a new database but want to check if database already present or not
any solution please help
Upvotes: 0
Views: 89
Reputation: 750
there is information available in the information schema.
SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'test';
If you don't have access to the information schema, you can run a command to create a database if it doesn't exist:
CREATE DATABASE IF NOT EXISTS my_tablename
Upvotes: 1