Skip to content
Think & Reflect · Q5

Q.• Which of the two insert statement should be used when the order of data to be inserted are not known?
• Can we insert two records with the same roll number?
[Context: the two INSERT forms taught in the chapter are —

(i) without column names: INSERT INTO STUDENT VALUES (3, 'Taleem Shah', '2002-02-28', NULL); and
(ii) with column names: INSERT INTO STUDENT (RollNumber, SName, SDateofBirth) VALUES (3, 'Taleem Shah', '2002-02-28');]
Tripura TbseTextbookSubjective· 2mImportance★★★★★est
56% · 53/95 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

When you don't know the order of columns in a table, use the explicit column-name form of INSERT to map values correctly; duplicate roll numbers are allowed unless a PRIMARY KEY or UNIQUE constraint exists.


The Two Forms of INSERT

SQL offers two syntaxes for inserting rows:

  1. Positional (implicit column order):

    INSERT INTO STUDENT VALUES (3, 'Taleem Shah', '2002-02-28', NULL);
    

    Values must appear in the exact order the columns were defined when the table was created. You must supply a value (or NULL) for every column.

  2. Explicit column names:

    INSERT INTO STUDENT (RollNumber, SName, SDateofBirth) 
    VALUES (3, 'Taleem Shah', '2002-02-28');
    

    You list the columns you want to fill, in any order you choose, and provide values in the same order. Omitted columns receive their default value or NULL.


Question 1: Which form when column order is unknown?

If you don't know the physical order of columns in the table — perhaps the schema was created by someone else, or columns were added over time — the explicit column-name form is the only safe choice.

Why? The positional form blindly maps the first value to the first column, the second to the second, and so on. If you guess the order wrong, you might insert a name into a date field or a roll number into a text field, causing type errors or silent data corruption.

The explicit form lets you write

INSERT INTO STUDENT (SName, RollNumber, SDateofBirth) 
VALUES ('Taleem Shah', 3, '2002-02-28');

even if the table's actual column order is RollNumber, SName, SDateofBirth, …. The database matches each value to the column you named, regardless of physical position.

Tip

Always prefer the explicit form in production code. It makes your INSERT self-documenting and immune to schema changes (new columns added at the end, for instance).


Question 2: Can we insert two records with the same roll number?

It depends on the table's constraints.

By default, SQL tables have no uniqueness requirement. You can insert

INSERT INTO STUDENT VALUES (3, 'Taleem Shah', '2002-02-28', NULL);
INSERT INTO STUDENT VALUES (3, 'Ananya Roy', '2003-05-15', NULL);

and both rows will be accepted. The table now contains two students with RollNumber = 3. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.