Search notes:

SQL Server: influence of logical errors on batches

In contrast to syntactical error, logical errors don't cause the current An SQL batch to be terminated:
-- -------------------------------------------------------------------
--
-- First Batch. No syntax errors
--

create table tq84_batch (id integer identity, txt varchar(20));
insert into tq84_batch (txt) values ('Batch 1 - a');

go

-- -------------------------------------------------------------------
--
-- Second batch: insert a few more records into the table.
--

insert into tq84_batch (txt) values ('Batch 2 - a');
insert into tq84_batch (txt) values ('Batch 2 - b');
insert into tq84_batch (txt) values ('Batch 2 - c');

go

-- -------------------------------------------------------------------
--
-- Third batch: This batch contains syntactical errors
--
-- This batch contains a logical error.
-- The error does not cause the batch to be terminated, the statement(s)
-- after the wrong error are still executed.
--

insert into tq84_batch (txt) values ('Batch 3 - a');
-- commit;

insert into tq84_batch (txt) values ('Batch 3 - b');
insert into tq84_batch (txt) values ('This string is much longer than 20 characters, hence, it is a logical error and cannot be executed.');

insert into tq84_batch (txt) values ('Batch 3 - c');

go

-- -------------------------------------------------------------------
--
-- fourth batch: show content of table and drop it.
--

select txt from tq84_batch order by id;
   --
   -- The select statement returns:
   --
   --     Batch 1 - a
   --     Batch 2 - a
   --     Batch 2 - b
   --     Batch 2 - c
   --     Batch 3 - a
   --     Batch 3 - b
   --     Batch 3 - c
   --

drop table tq84_batch;

go
Github repository about-MSSQL, path: /sql/go/batches-with-logical-errors.sql

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759406537, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/SQL-Server/sql/batch/batches-with-logical-errors(93): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78