And Another ChatGPT Example…

Again, without comment, a “conversation” with ChatGPT research preview [announcement] that follows on, in part, from this and that

Generate a practical activity that requires students to generate SQL code that can be used to demonstrate atomicity failure in a relational database. Also provide a marking scheme with a maximum score of 11 marks.

Me to ChatGPT
Practical activity:

Have students create a simple relational database with three tables: Customers, Orders, and OrderItems.

Have students create a SQL query that inserts a new customer into the Customers table, along with a new order and order items into the Orders and OrderItems tables, respectively.

Have students run the query multiple times and observe that the data is correctly inserted into all tables.

Have students modify the query to simulate an atomicity failure by intentionally introducing a syntax error or other issue that causes the query to fail.

Have students run the query again and observe that the data is not inserted into any of the tables, demonstrating atomicity failure.

Have students explain what happened and how they would prevent atomicity failures in a real-world scenario.

Marking scheme:

Correctly create the three tables (2 marks)
Correctly insert data into all tables using the original query (2 marks)
Correctly modify the query to simulate atomicity failure (2 marks)
Correctly demonstrate atomicity failure by running the modified query (2 marks)
Correctly explain what happened and how to prevent atomicity failures (3 marks)

Total: 11 marks

Provide a worked example from an average student that scores 6 marks

Me to ChatGPT
Example:

The student correctly creates the three tables (2 marks):
CREATE TABLE Customers (
  id INTEGER PRIMARY KEY,
  name VARCHAR(255) NOT NULL
);

CREATE TABLE Orders (
  id INTEGER PRIMARY KEY,
  customer_id INTEGER NOT NULL,
  FOREIGN KEY (customer_id) REFERENCES Customers (id)
);

CREATE TABLE OrderItems (
  id INTEGER PRIMARY KEY,
  order_id INTEGER NOT NULL,
  FOREIGN KEY (order_id) REFERENCES Orders (id)
);
The student correctly inserts data into all tables using the original query (2 marks):
BEGIN TRANSACTION;

INSERT INTO Customers (id, name) VALUES (1, 'John Doe');

INSERT INTO Orders (id, customer_id) VALUES (1, 1);

INSERT INTO OrderItems (id, order_id) VALUES (1, 1), (2, 1), (3, 1);

COMMIT;

The student incorrectly modifies the query to simulate atomicity failure (0 marks):
BEGIN TRANSACTION;

INSERT INTO Customers (id, name) VALUES (1, 'John Doe');

INSERT INTO Orders (id, customer_id) VALUES (1, 1);

INSERT INTO OrderItems (id, order_id) VALUES (1, 1), (2, 1), (3, 1);

ROLLBACK;

In this example, the student used the ROLLBACK statement instead of COMMIT, which would have the opposite effect of what they intended. Instead of simulating atomicity failure, this query would actually prevent atomicity failure by rolling back any changes made during the transaction.

The student correctly demonstrates atomicity failure by running the modified query (2 marks):
BEGIN TRANSACTION;

INSERT INTO Customers (id, name) VALUES (1, 'John Doe');

INSERT INTO Orders (id, customer_id) VALUES (1, 1);

-- Syntax error causes the query to fail
INSERT INTO OrderItems (id, order_id) VALUES (1, 1), (2, 1), (3, 1)

COMMIT;

In this example, the student introduced a syntax error by leaving out the closing parentheses on the INSERT statement for the OrderItems table. This caused the query to fail and resulted in atomicity failure, where none of the data was inserted into any of the tables.

The student correctly explains what happened and how to prevent atomicity failures (2 marks):
"Atomicity failure occurred because our query failed due to a syntax error. To prevent this, we should always make sure our queries are correct and test them before running them in a transaction. We can also use a TRY-CATCH block to handle any errors that may occur and roll back the transaction if necessary."

Total: 6 marks

Provide an example answer that scores full marks.

Me to ChatGPT
Example:

The student correctly creates the three tables (2 marks):
CREATE TABLE Customers (
  id INTEGER PRIMARY KEY,
  name VARCHAR(255) NOT NULL
);

CREATE TABLE Orders (
  id INTEGER PRIMARY KEY,
  customer_id INTEGER NOT NULL,
  FOREIGN KEY (customer_id) REFERENCES Customers (id)
);

CREATE TABLE OrderItems (
  id INTEGER PRIMARY KEY,
  order_id INTEGER NOT NULL,
  FOREIGN KEY (order_id) REFERENCES Orders (id)
);

The student correctly inserts data into all tables using the original query (2 marks):
BEGIN TRANSACTION;

INSERT INTO Customers (id, name) VALUES (1, 'John Doe');

INSERT INTO Orders (id, customer_id) VALUES (1, 1);

INSERT INTO OrderItems (id, order_id) VALUES (1, 1), (2, 1), (3, 1);

COMMIT;

The student correctly modifies the query to simulate atomicity failure (2 marks):
BEGIN TRANSACTION;

INSERT INTO Customers (id, name) VALUES (1, 'John Doe');

INSERT INTO Orders (id, customer_id) VALUES (1, 1);

-- Syntax error causes the query to fail
INSERT INTO OrderItems (id, order_id) VALUES (1, 1), (2, 1), (3, 1)

COMMIT;

In this example, the student introduced a syntax error by leaving out the closing parentheses on the INSERT statement for the OrderItems table. This caused the query to fail and would result in atomicity failure, where none of the data would be inserted into any of the tables.

The student correctly demonstrates atomicity failure by running the modified query (2 marks):
BEGIN TRANSACTION;

INSERT INTO Customers (id, name) VALUES (1, 'John Doe');

INSERT INTO Orders (id, customer_id) VALUES (1, 1);

-- Syntax error causes the query to fail
INSERT INTO OrderItems (id, order_id) VALUES (1, 1), (2, 1), (3, 1)

COMMIT;

In this example, the student introduced a syntax error by leaving out the closing parentheses on the INSERT statement for the OrderItems table. This caused the query to fail and resulted in atomicity failure, where none of the data was inserted into any of the tables.

The student correctly explains what happened and how to prevent atomicity failures (3 marks):
"Atomicity failure occurred because our query failed due to a syntax error. To prevent this, we should always make sure our queries are correct and test them before running them in a transaction. We can also use a TRY-CATCH block to handle any errors that may occur and roll back the transaction if necessary. Additionally, we can use transaction isolation levels to control how transactions interact with each other and prevent issues such as dirty reads and lost updates."

Total: 11 marks

Compare the two answers and identify the similarities and differences between them.

Me to ChatGPT
Both answers correctly create the three tables and insert data into all tables using the original query.

The main difference between the answers is in how they simulate atomicity failure. The first answer uses the ROLLBACK statement instead of COMMIT, which would have the opposite effect of what they intended. The second answer introduces a syntax error, which would cause the query to fail and result in atomicity failure.

Both answers correctly demonstrate atomicity failure by running the modified query, but the second answer includes a more detailed explanation of what happened and how to prevent atomicity failures in the future. This is reflected in the marking scheme, where the second answer receives full marks while the first answer only receives 6 out of 11 marks.

Create an assessment to assess an undergraduate student’s understanding of ACID compliance in a relational database.The question should incorporate the previously described practical activity. Then provide an updated marking guide that scores the assessment as a whole out of 15 marks.

Me to ChatGTP
Assessment:

Explain the ACID compliance properties of a relational database and how they ensure data consistency and integrity. (2 marks)

Create a simple relational database with three tables: Customers, Orders, and OrderItems. (2 marks)

Write a SQL query that inserts a new customer into the Customers table, along with a new order and order items into the Orders and OrderItems tables, respectively. (2 marks)

Run the query multiple times and observe that the data is correctly inserted into all tables. (2 marks)

Modify the query to simulate an atomicity failure by intentionally introducing a syntax error or other issue that causes the query to fail. (2 marks)

Run the query again and observe that the data is not inserted into any of the tables, demonstrating atomicity failure. (2 marks)

Explain what happened and how you would prevent atomicity failures in a real-world scenario. (3 marks)

Updated marking guide:

Correctly explain the ACID compliance properties of a relational database (2 marks)
Correctly create the three tables (2 marks)
Correctly insert data into all tables using the original query (2 marks)
Correctly demonstrate correct data insertion by running the original query multiple times (2 marks)
Correctly modify the query to simulate atomicity failure (2 marks)
Correctly demonstrate atomicity failure by running the modified query (2 marks)
Correctly explain what happened and how to prevent atomicity failures (3 marks)

Total: 15 marks

Provide an example answer that scores a poor mark of 5 marks and that includes several spelling errors.

Me to ChatGPT
Example:

The student incorrectly explains the ACID compliance properties of a relational database (0 marks):
"ACID compliance ensures that data is consistant and integrety is maintained in a relational database. Atomicity means that all actions in a transaction either happen or not. Consistancy means that the database is in a valid state at all times. Isolation means that transactions don't interfere with each other. Durability means that once a transaction is commited, it can't be undone."

In this example, the student has several spelling errors and misunderstands the meaning of some of the ACID compliance properties. Atomicity does not guarantee that all actions in a transaction will happen, but rather that they will either all happen or none will happen. Consistency does not mean that the database is always in a valid state, but rather that it will be in a valid state after the transaction is completed.

The student correctly creates the three tables (2 marks):
CREATE TABLE Customers (
  id INTEGER PRIMARY KEY,
  name VARCHAR(255) NOT NULL
);

CREATE TABLE Orders (
  id INTEGER PRIMARY KEY,
  customer_id INTEGER NOT NULL,
  FOREIGN KEY (customer_id) REFERENCES Customers (id)
);

CREATE TABLE OrderItems (
  id INTEGER PRIMARY KEY,
  order_id INTEGER NOT NULL,
  FOREIGN KEY (order_id) REFERENCES Orders (id)
);

The student correctly inserts data into all tables using the original query (2 marks):
BEGIN TRANSACTION;

INSERT INTO Customers (id, name) VALUES (1, 'John Doe');

INSERT INTO Orders (id, customer_id) VALUES (1, 1);

INSERT INTO OrderItems (id, order_id) VALUES (1, 1), (2, 1), (3, 1);

COMMIT;

The student does not demonstrate correct data insertion by running the original query multiple times (0 marks)

The student does not modify the query to simulate atomicity failure (0 marks)

The student does not demonstrate atomicity failure by running the modified query (0 marks)

The student does not explain what happened and how to prevent atomicity failures (1 mark):

"Atomicity failure occurs when a transaction fails. To prevent this, we need to make sure our queries are correct and test them before running them in a transaction."

In this example, the student does not complete any of the required steps to demonstrate atomicity failure and provide a proper explanation. They only provide a brief, incomplete explanation of what atomicity failure is.

Total: 5 marks

Now provide an example of an excellent solution that includes commented code.

Me to ChatGPT
Example:

The student correctly explains the ACID compliance properties of a relational database (2 marks):
"ACID compliance ensures data consistency and integrity in a relational database. Atomicity guarantees that all actions in a transaction either happen or none happen, preventing partial updates. Consistency ensures that the database is always in a valid state after a transaction is completed. Isolation prevents transactions from interfering with each other, while durability ensures that committed transactions cannot be undone."

The student correctly creates the three tables and includes comments to explain each table and its purpose (2 marks):
-- Customers table stores information about customers
CREATE TABLE Customers (
  id INTEGER PRIMARY KEY, -- Primary key for the table
  name VARCHAR(255) NOT NULL -- Customer's name
);

-- Orders table stores information about orders made by customers
CREATE TABLE Orders (
  id INTEGER PRIMARY KEY, -- Primary key for the table
  customer_id INTEGER NOT NULL, -- Foreign key referencing the Customers table
  FOREIGN KEY (customer_id) REFERENCES Customers (id)
);

-- OrderItems table stores information about items in each order
CREATE TABLE OrderItems (
  id INTEGER PRIMARY KEY, -- Primary key for the table
  order_id INTEGER NOT NULL, -- Foreign key referencing the Orders table
  FOREIGN KEY (order_id) REFERENCES Orders (id)
);

The student correctly inserts data into all tables using the original query and includes comments to explain each step (2 marks):
BEGIN TRANSACTION; -- Start a new transaction

-- Insert a new customer into the Customers table
INSERT INTO Customers (id, name) VALUES (1, 'John Doe');

-- Insert a new order into the Orders table
INSERT INTO Orders (id, customer_id) VALUES (1, 1);

-- Insert order items into the OrderItems table
INSERT INTO OrderItems (id, order_id) VALUES (1, 1), (2, 1), (3, 1);

COMMIT; -- End the transaction and commit the changes

The student correctly demonstrates correct data insertion by running the original query multiple times and includes comments to explain the results (2 marks):
-- Run the query multiple times
BEGIN TRANSACTION;
INSERT INTO Customers (id, name) VALUES (1, 'John Doe');
INSERT INTO Orders (id, customer_id) VALUES (1, 1);
INSERT INTO OrderItems (id, order_id) VALUES (1, 1), (2, 1), (3, 1);
COMMIT;

-- Observe that the data is correctly inserted into all tables each time
SELECT * FROM Customers;
SELECT * FROM Orders;
SELECT * FROM OrderItems;

The student correctly modifies the query to simulate atomicity failure and includes comments to explain the change (2 marks):
-- Modify the query to introduce a syntax error
BEGIN TRANSACTION;
INSERT INTO Customers (id, name) VALUES (1, 'John Doe');
INSERT INTO Orders (id, customer_id) VALUES (1, 1);
-- Syntax error: missing closing parentheses
INSERT INTO OrderItems (id, order_id) VALUES (1, 1), (2, 1),

Provide some feedback for the student who performed badly, referencing the marking guide and expliaing how they could improve their performance.

Me to ChatGPT
To the third student:

Your performance on this assessment was not up to par. According to the marking guide, you only received 5 out of 15 marks.

To improve your performance, you should focus on the following areas:

Explanation of the ACID compliance properties (0/2 marks): Your explanation was incomplete and contained several spelling errors. To improve, you should thoroughly research and understand the topic before attempting to explain it.

Creation of the three tables (2/2 marks): You did a good job of creating the tables and including comments to explain their purpose.

Insertion of data using the original query (2/2 marks): You correctly inserted data into all tables using the original query.

Demonstration of correct data insertion (0/2 marks): You did not demonstrate correct data insertion by running the original query multiple times. To improve, you should run the query multiple times and observe that the data is correctly inserted into all tables.

Modification of the query to simulate atomicity failure (0/2 marks): You did not modify the query to simulate atomicity failure. To improve, you should modify the query to intentionally introduce a syntax error or other issue that causes the query to fail.

Demonstration of atomicity failure (0/2 marks): You did not demonstrate atomicity failure by running the modified query. To improve, you should run the modified query and observe that the data is not inserted into any of the tables.

Explanation of what happened and how to prevent atomicity failures (1/3 marks): Your explanation was brief and incomplete. To improve, you should provide a detailed explanation of what happened and how to prevent atomicity failures in real-world scenarios. This could include using transaction isolation levels and handling errors with a TRY-CATCH block.

In summary, to improve your performance on future assessments, you should thoroughly research and understand the topic, complete all required steps, and provide detailed explanations and examples. Additionally, make sure to proofread your work and correct any spelling or grammar errors.

For the poor student, provide example tutor feedback correcting the student’s code error.

Me to ChatGPT
To the third student:

It looks like you introduced a syntax error in your SQL code when simulating atomicity failure. In your modified query, you forgot to include the closing parentheses on the INSERT statement for the OrderItems table. This caused the query to fail and resulted in atomicity failure.

To fix the error, you can simply add the missing closing parentheses:
BEGIN TRANSACTION;

INSERT INTO Customers (id, name) VALUES (1, 'John Doe');

INSERT INTO Orders (id, customer_id) VALUES (1, 1);

-- Add missing closing parentheses
INSERT INTO OrderItems (id, order_id) VALUES (1, 1), (2, 1), (3, 1);

COMMIT;

With this change, the query should run successfully and demonstrate atomicity failure by not inserting any data into the tables.

Remember to always carefully proofread your code and test it before running it in a transaction. This will help prevent issues like this and ensure that your transactions are successful.

If you feel you are able to trust the responses enough not to be beguiled by them, and with enough knowledge to know whether they are incorrect or not so that can do an effective “academic” editorial job on them (if required…;-), the next question that arises is: can we automate the generation of prompts to automate assessment generation, marking and feedback? We might also ask whether we can easily provide top-up training with reference to our own course materials that would let us efficiently make use of prompts such as: Provide some feedback for the student who performed badly, referencing the marking guide and including links to appropriate parts of the course material explaining how they could improve their performance. The next next question is how do we develop student curiosity so that can engage in such conversations themselves, bearing in mind the ChatGPT agent may actually be an unreliable narrator and cannot necessarily be trusted to give an answer that is not potentially misleading, if not accuarately incorrect, whilst also recognising that certain responses may be incorrect, internally inconsistent at the question level (e.g. dodgy arithmetic here, inconsistent application of the same rules applid to different texts in here).

Increasingly, I think the unreliable narrator may provided one useful way of framing certain sorts of interaction with machine generated content…

Author: Tony Hirst

I'm a Senior Lecturer at The Open University, with an interest in #opendata policy and practice, as well as general web tinkering...

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: