Know if DataBase dont have tables

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
fsandoval
Posts: 2
Joined: Tue 18 Jul 2006 16:23

Know if DataBase dont have tables

Post by fsandoval » Tue 18 Jul 2006 16:27

Hi for all, I make test with this component but i need to do 2 things.
1 .- Create a Dabate
2.- How i can know if database is doesnt has tables, for create those.

i working cbuilder.


regards.
fernando sandoval ruiz

Zagawa
Posts: 21
Joined: Fri 12 May 2006 09:56

Post by Zagawa » Wed 19 Jul 2006 06:04

Hi,

For your second question

Code: Select all

select S.`schema_name` from `information_schema`.`schemata` S
where S.`schema_name` not in
( select T.`table_schema`
from `information_schema`.`TABLES` T where
T.`table_schema`=S.`SCHEMA_NAME` )
and S.`schema_name` = 'dbname';
This query will return empty result if 'dbname' doesn't have table.

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Wed 19 Jul 2006 09:33

These are common questions of SQL for MySQL Server usage.
> 1 .- Create a Dabate
To create database you should execute a command like CREATE DATABASE database_name;

> 2.- How i can know if database is doesnt has tables, for create those.
You should use GetTableNames method of TMyConnection or SHOW TABLES command of MySQL Server. Also you should pay attention on following commands: DROP TABLE IF EXISTS and CREATE TABLE IF NOT EXISTS.

For more information read MySQL Reference Manual.

fsandoval
Posts: 2
Joined: Tue 18 Jul 2006 16:23

Thanks.

Post by fsandoval » Wed 19 Jul 2006 15:04

Many thanks, for you help.

Post Reply