Difference between revisions of "Insert Queries"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "INSERT adds rows to an existing table, there can be different syntax depending on specific version of SQL etc ==Best Method== <SyntaxHighlight lang=sql> INSERT INTO table ...")
 
(Basic Quiz)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
INSERT adds rows to an existing table, there can be different syntax depending on specific version of SQL etc
+
INSERT adds rows to an existing table, there can be different syntax depending on specific version of SQL etc. For exam questions use one of the methods below. Also remember the values inserted should match the data types of the table fields.
  
 
==Best Method==
 
==Best Method==
  
 
<SyntaxHighlight lang=sql>
 
<SyntaxHighlight lang=sql>
  INSERT INTO table
+
  INSERT INTO table_name
 
  (field1, field2, field3)
 
  (field1, field2, field3)
 
  VALUES
 
  VALUES
Line 12: Line 12:
 
==Alternative Method==
 
==Alternative Method==
 
<SyntaxHighlight lang=sql>
 
<SyntaxHighlight lang=sql>
  INSERT INTO table
+
  INSERT INTO table_name
 
  VALUES
 
  VALUES
 
  (value1, value2, value3);
 
  (value1, value2, value3);
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
===Basic Quiz===
 +
All these questions will use this table called Employees:
 +
 +
[[File:Capture.png]]
 +
<quiz display=simple>
 +
 +
{which of the following Insert the following record:
 +
{| class="wikitable"
 +
|-
 +
| Joe || Bloggs || 1 Some Street || Sheffield || 35
 +
|}
 +
 +
|type="()"}
 +
+ Insert Into Employees ('First Name', 'Last Name', 'Address', 'City', 'Age') Values ('Joe', 'Bloggs', '1 Some Street', 'Sheffield', 35)
 +
||Correct
 +
- Insert Into Employees ('First Name', 'Last Name', 'Address', 'City', 'Age') Data ('Joe', 'Bloggs', '1 Some Street', 'Sheffield', 35)
 +
||Incorrect
 +
- Insert Into Employees ('First Name', 'Last Name', 'Address', 'Age', 'City') Data ('Joe', 'Bloggs', '1 Some Street', 'Sheffield', 35)
 +
||Incorrect
 +
- Insert Into Employees ('First Name', 'Last Name', 'Address', 'Age', 'City') Values ('Joe', 'Bloggs', '1 Some Street', 'Sheffield', 35)
 +
||Incorrect
 +
 +
{which of the following statements will Insert the following record:
 +
{| class="wikitable"
 +
|-
 +
| Fred || Danson || 12 East Road || Leeds || 60
 +
|}
 +
 +
1) Insert Into Employees ('First Name', 'Last Name', 'Address', 'City', 'Age') Values ('Fred', 'Danson', '12 East Road', 'Leeds', 60)
 +
 +
2) Insert Into Employees  Values ('Fred', 'Danson', '12 East Road', 'Leeds', 60)
 +
 +
3) Insert Into Employees  Values ('Fred', 'Danson', '12 East Road',  60, 'Leeds')
 +
 +
 +
|type="()"}
 +
- 1 & 2 & 3
 +
||Incorrect
 +
+ 1 & 2
 +
||Correct
 +
- 1 Only
 +
||Incorrect
 +
- 2 Only
 +
||Incorrect
 +
 +
</quiz>

Latest revision as of 10:13, 28 September 2020

INSERT adds rows to an existing table, there can be different syntax depending on specific version of SQL etc. For exam questions use one of the methods below. Also remember the values inserted should match the data types of the table fields.

Best Method

 INSERT INTO table_name
 (field1, field2, field3)
 VALUES
 (value1, value2, value3);

Alternative Method

 INSERT INTO table_name
 VALUES
 (value1, value2, value3);

Basic Quiz

All these questions will use this table called Employees:

Capture.png

1. which of the following Insert the following record:

Joe Bloggs 1 Some Street Sheffield 35
Insert Into Employees ('First Name', 'Last Name', 'Address', 'City', 'Age') Values ('Joe', 'Bloggs', '1 Some Street', 'Sheffield', 35)
Correct
Insert Into Employees ('First Name', 'Last Name', 'Address', 'City', 'Age') Data ('Joe', 'Bloggs', '1 Some Street', 'Sheffield', 35)
Incorrect
Insert Into Employees ('First Name', 'Last Name', 'Address', 'Age', 'City') Data ('Joe', 'Bloggs', '1 Some Street', 'Sheffield', 35)
Incorrect
Insert Into Employees ('First Name', 'Last Name', 'Address', 'Age', 'City') Values ('Joe', 'Bloggs', '1 Some Street', 'Sheffield', 35)
Incorrect

2. which of the following statements will Insert the following record:

Fred Danson 12 East Road Leeds 60

1) Insert Into Employees ('First Name', 'Last Name', 'Address', 'City', 'Age') Values ('Fred', 'Danson', '12 East Road', 'Leeds', 60)

2) Insert Into Employees Values ('Fred', 'Danson', '12 East Road', 'Leeds', 60)

3) Insert Into Employees Values ('Fred', 'Danson', '12 East Road', 60, 'Leeds')

1 & 2 & 3
Incorrect
1 & 2
Correct
1 Only
Incorrect
2 Only
Incorrect

Your score is 0 / 0