Bird
0
0

What will be the effect of executing the following up() method in a migration?

medium📝 Predict Output Q4 of 15
NestJS - Database with TypeORM
What will be the effect of executing the following up() method in a migration?
await queryRunner.query(`CREATE TABLE products (id int PRIMARY KEY, name varchar(255))`);
AThe 'products' table will have a new column added
BThe existing 'products' table will be dropped
CA new table named 'products' with columns 'id' and 'name' will be created
DThe migration will fail because the syntax is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the SQL query

    The query is a CREATE TABLE statement for 'products' with columns 'id' and 'name'.
  2. Step 2: Understand migration effect

    Running this will create a new table named 'products' with specified columns.
  3. Final Answer:

    A new table named 'products' with columns 'id' and 'name' will be created -> Option C
  4. Quick Check:

    CREATE TABLE creates tables [OK]
Quick Trick: CREATE TABLE adds new tables to the database [OK]
Common Mistakes:
  • Confusing CREATE TABLE with DROP TABLE
  • Assuming columns are added to existing tables
  • Thinking the query syntax is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes