0

Hii ,

I am a bit new to SQL and would like some help to solve the following problem.

I have a database X which contains a table TABLE with column named domain.I retrieve these values and create one database for each value with that value as the database name . For example , if the domain has the values value1, value2, value3 there should be three databases created with names value1 , value2 and value3...and when i add a value to the TABLE in database X , a new database should be created with the value X.TABLE.domainvalue ... I need to write an SQLScript that accomplishes this.

Any help would be appreciated.

Links that would help me understand better are welcome.

1
  • And seriosuly, don't even consider naming a table TABLE. Commented Jan 19, 2011 at 20:44

1 Answer 1

1

Try this :

CREATE PROCEDURE procCreateDataBase()
BEGIN
  DECLARE domainName CHAR(50);
  DECLARE cur1 CURSOR FOR SELECT domain FROM databaseX.domainNames;

  OPEN cur1;

  LOOP
    FETCH cur1 INTO domainName;
      CREATE DATABASE IF NOT EXISTS domainName;
  END LOOP;

  CLOSE cur1;
END;

This is a stored procedure you can call anytime and that will create your databases depending on the domains found, if they don't already exist.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.