I would like to know if anyone can help me solve a problem encountered when writing multiple user entries to a file using the same method. a FOR cycle.
In my code, I ask the user to enter the details of a database, step by step. I first ask for the name of the database, then you must enter the number of tables you want to create, then later in the cycle, you are asked to enter the name of each of the tables.
The results of user input are written to an SQL file. My problem is that the variables that the user enters are not written correctly. This occurs during the cycle, the% counter% variable remains empty ALWAYS at the first iteration and the following iterations correspond to the previous values of the variable. Here, I leave the part of the code that causes me problems.
@ECHO OFF set counter = 1 set / p System = Enter the name of the system: set / p noTables = Enter the number of tables you want to create in the database: set end =); echo CREATE DATABASE% System%; > DB.sql echo USE DATABASE% System%; >> DB.sql : cycle1 if% counter% LEQ% noTables% ( set / p tableName = Name of the following table: set nextTable =% tableName% echo CREATE TABLE% nextTable% ^ (>> DB.sql set / to counter = counter + 1 goto: cycle1 ) if not ( goto: go out ) :go out pause
Assuming that the user enters "3" in the number of tables and entering the table names under "table 1" "table 2" "table 3". This is the result that is written in the SQL file
CREATE DATABASE system; USE DATABASE System; CREATE THE TABLE ( CREATE THE TABLE ( CREATE TABLE table 1 (