diff --git a/core/lib/Drupal/Core/Entity/entity.api.php b/core/lib/Drupal/Core/Entity/entity.api.php
index 5387c7ef7e..c4b6e04411 100644
--- a/core/lib/Drupal/Core/Entity/entity.api.php
+++ b/core/lib/Drupal/Core/Entity/entity.api.php
@@ -943,7 +943,7 @@ function hook_ENTITY_TYPE_presave(Drupal\Core\Entity\EntityInterface $entity) {
  */
 function hook_entity_insert(Drupal\Core\Entity\EntityInterface $entity) {
   // Insert the new entity into a fictional table of all entities.
-  db_insert('example_entity')
+  \Drupal::database()->insert('example_entity')
     ->fields([
       'type' => $entity->getEntityTypeId(),
       'id' => $entity->id(),
@@ -967,7 +967,7 @@ function hook_entity_insert(Drupal\Core\Entity\EntityInterface $entity) {
  */
 function hook_ENTITY_TYPE_insert(Drupal\Core\Entity\EntityInterface $entity) {
   // Insert the new entity into a fictional table of this type of entity.
-  db_insert('example_entity')
+  \Drupal::database()->insert('example_entity')
     ->fields([
       'id' => $entity->id(),
       'created' => REQUEST_TIME,
diff --git a/core/modules/contact/tests/drupal-7.contact.database.php b/core/modules/contact/tests/drupal-7.contact.database.php
index bd36384d7e..7145c71cdc 100644
--- a/core/modules/contact/tests/drupal-7.contact.database.php
+++ b/core/modules/contact/tests/drupal-7.contact.database.php
@@ -16,7 +16,7 @@
   ->execute();
 
 // Add a custom contact category.
-db_insert('contact')->fields([
+\Drupal::database()->insert('contact')->fields([
   'category',
   'recipients',
   'reply',
diff --git a/core/modules/file/tests/src/Kernel/UsageTest.php b/core/modules/file/tests/src/Kernel/UsageTest.php
index 672de0fb5a..9e1bcb81ae 100644
--- a/core/modules/file/tests/src/Kernel/UsageTest.php
+++ b/core/modules/file/tests/src/Kernel/UsageTest.php
@@ -20,7 +20,7 @@ class UsageTest extends FileManagedUnitTestBase {
    */
   public function testGetUsage() {
     $file = $this->createFile();
-    db_insert('file_usage')
+    \Drupal::database()->insert('file_usage')
       ->fields([
         'fid' => $file->id(),
         'module' => 'testing',
@@ -29,7 +29,7 @@ public function testGetUsage() {
         'count' => 1
       ])
       ->execute();
-    db_insert('file_usage')
+    \Drupal::database()->insert('file_usage')
       ->fields([
         'fid' => $file->id(),
         'module' => 'testing',
@@ -80,7 +80,7 @@ public function testAddUsage() {
   public function testRemoveUsage() {
     $file = $this->createFile();
     $file_usage = $this->container->get('file.usage');
-    db_insert('file_usage')
+    \Drupal::database()->insert('file_usage')
       ->fields([
         'fid' => $file->id(),
         'module' => 'testing',
diff --git a/core/modules/history/src/Tests/Views/HistoryTimestampTest.php b/core/modules/history/src/Tests/Views/HistoryTimestampTest.php
index 4766538392..45003c9953 100644
--- a/core/modules/history/src/Tests/Views/HistoryTimestampTest.php
+++ b/core/modules/history/src/Tests/Views/HistoryTimestampTest.php
@@ -40,14 +40,14 @@ public function testHandlers() {
     $this->drupalLogin($account);
     \Drupal::currentUser()->setAccount($account);
 
-    db_insert('history')
+    \Drupal::database()->insert('history')
       ->fields([
         'uid' => $account->id(),
         'nid' => $nodes[0]->id(),
         'timestamp' => REQUEST_TIME - 100,
       ])->execute();
 
-    db_insert('history')
+    \Drupal::database()->insert('history')
       ->fields([
         'uid' => $account->id(),
         'nid' => $nodes[1]->id(),
diff --git a/core/modules/locale/src/Tests/LocaleUpdateBase.php b/core/modules/locale/src/Tests/LocaleUpdateBase.php
index b228a962de..f9ee8509fd 100644
--- a/core/modules/locale/src/Tests/LocaleUpdateBase.php
+++ b/core/modules/locale/src/Tests/LocaleUpdateBase.php
@@ -279,7 +279,7 @@ protected function setCurrentTranslations() {
     ];
     foreach ($data as $file) {
       $file = array_merge($default, $file);
-      db_insert('locale_file')->fields($file)->execute();
+      \Drupal::database()->insert('locale_file')->fields($file)->execute();
     }
   }
 
diff --git a/core/modules/node/node.install b/core/modules/node/node.install
index 4e2c24098e..f8accb4325 100644
--- a/core/modules/node/node.install
+++ b/core/modules/node/node.install
@@ -134,7 +134,7 @@ function node_install() {
   }
 
   // Populate the node access table.
-  db_insert('node_access')
+  \Drupal::database()->insert('node_access')
     ->fields([
       'nid' => 0,
       'gid' => 0,
diff --git a/core/modules/node/src/Tests/NodeQueryAlterTest.php b/core/modules/node/src/Tests/NodeQueryAlterTest.php
index c502d6c9ed..3fe00335c9 100644
--- a/core/modules/node/src/Tests/NodeQueryAlterTest.php
+++ b/core/modules/node/src/Tests/NodeQueryAlterTest.php
@@ -151,7 +151,7 @@ public function testNodeQueryAlterOverride() {
       'grant_update' => 0,
       'grant_delete' => 0,
     ];
-    db_insert('node_access')->fields($record)->execute();
+    \Drupal::database()->insert('node_access')->fields($record)->execute();
 
     // Test that the noAccessUser still doesn't have the 'view'
     // privilege after adding the node_access record.
diff --git a/core/modules/node/tests/src/Functional/NodeAccessGrantsCacheContextTest.php b/core/modules/node/tests/src/Functional/NodeAccessGrantsCacheContextTest.php
index fa2116ab87..5a94f3a672 100644
--- a/core/modules/node/tests/src/Functional/NodeAccessGrantsCacheContextTest.php
+++ b/core/modules/node/tests/src/Functional/NodeAccessGrantsCacheContextTest.php
@@ -92,7 +92,7 @@ public function testCacheContext() {
       'grant_update' => 0,
       'grant_delete' => 0,
     ];
-    db_insert('node_access')->fields($record)->execute();
+    \Drupal::database()->insert('node_access')->fields($record)->execute();
 
     // Put user accessUser (uid 0) in the realm.
     \Drupal::state()->set('node_access_test.no_access_uid', 0);
diff --git a/core/modules/path/path.api.php b/core/modules/path/path.api.php
index df20b95e90..60092e9a5c 100644
--- a/core/modules/path/path.api.php
+++ b/core/modules/path/path.api.php
@@ -20,7 +20,7 @@
  * @see \Drupal\Core\Path\PathInterface::save()
  */
 function hook_path_insert($path) {
-  db_insert('mytable')
+  \Drupal::database()->insert('mytable')
     ->fields([
       'alias' => $path['alias'],
       'pid' => $path['pid'],
diff --git a/core/modules/search/search.module b/core/modules/search/search.module
index ae99a8731e..46d577ab7b 100644
--- a/core/modules/search/search.module
+++ b/core/modules/search/search.module
@@ -523,7 +523,7 @@ function search_index($type, $sid, $langcode, $text) {
   search_index_clear($type, $sid, $langcode);
 
   // Insert cleaned up data into dataset
-  db_insert('search_dataset')
+  \Drupal::database()->insert('search_dataset')
     ->fields([
       'sid' => $sid,
       'langcode' => $langcode,
diff --git a/core/modules/search/src/Tests/SearchRankingTest.php b/core/modules/search/src/Tests/SearchRankingTest.php
index 28241d2af2..821a8725dd 100644
--- a/core/modules/search/src/Tests/SearchRankingTest.php
+++ b/core/modules/search/src/Tests/SearchRankingTest.php
@@ -101,7 +101,7 @@ public function testRankings() {
     // to the Statistics module. So instead go ahead and manually update the
     // counter for this node.
     $nid = $nodes['views'][1]->id();
-    db_insert('node_counter')
+    \Drupal::database()->insert('node_counter')
       ->fields(['totalcount' => 5, 'daycount' => 5, 'timestamp' => REQUEST_TIME, 'nid' => $nid])
       ->execute();
 
diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module
index 8b1cc2398b..5a4fa87c39 100644
--- a/core/modules/simpletest/simpletest.module
+++ b/core/modules/simpletest/simpletest.module
@@ -138,7 +138,7 @@ function simpletest_run_tests($test_list) {
     unset($test_list['phpunit']);
   }
 
-  $test_id = db_insert('simpletest_test_id')
+  $test_id = \Drupal::database()->insert('simpletest_test_id')
     ->useDefaults(['test_id'])
     ->execute();
 
diff --git a/core/modules/system/tests/modules/module_test/module_test.install b/core/modules/system/tests/modules/module_test/module_test.install
index 5f3f6f654c..313a5f07dc 100644
--- a/core/modules/system/tests/modules/module_test/module_test.install
+++ b/core/modules/system/tests/modules/module_test/module_test.install
@@ -29,7 +29,7 @@ function module_test_schema() {
  */
 function module_test_install() {
   $schema = drupal_get_module_schema('module_test', 'module_test');
-  db_insert('module_test')
+  \Drupal::database()->insert('module_test')
     ->fields([
       'data' => $schema['fields']['data']['type'],
     ])
diff --git a/core/modules/tracker/tracker.module b/core/modules/tracker/tracker.module
index dbde704a5a..3263181015 100644
--- a/core/modules/tracker/tracker.module
+++ b/core/modules/tracker/tracker.module
@@ -69,7 +69,7 @@ function tracker_cron() {
         ->execute();
 
       // Insert the node-level data.
-      db_insert('tracker_node')
+      \Drupal::database()->insert('tracker_node')
         ->fields([
           'nid' => $nid,
           'published' => $node->isPublished(),
@@ -78,7 +78,7 @@ function tracker_cron() {
         ->execute();
 
       // Insert the user-level data for the node's author.
-      db_insert('tracker_user')
+      \Drupal::database()->insert('tracker_user')
         ->fields([
           'nid' => $nid,
           'published' => $node->isPublished(),
@@ -101,7 +101,7 @@ function tracker_cron() {
         ->groupBy('uid')
         ->execute();
       if ($result) {
-        $query = db_insert('tracker_user');
+        $query = \Drupal::database()->insert('tracker_user');
         foreach ($result as $row) {
           $query->fields([
             'uid' => $row['uid'],
diff --git a/core/modules/user/user.api.php b/core/modules/user/user.api.php
index 364dd1ac63..dcd1b73c89 100644
--- a/core/modules/user/user.api.php
+++ b/core/modules/user/user.api.php
@@ -148,7 +148,7 @@ function hook_user_login($account) {
  *   The user object on which the operation was just performed.
  */
 function hook_user_logout($account) {
-  db_insert('logouts')
+  \Drupal::database()->insert('logouts')
     ->fields([
       'uid' => $account->id(),
       'time' => time(),
diff --git a/core/modules/views/src/Tests/Plugin/StyleTableTest.php b/core/modules/views/src/Tests/Plugin/StyleTableTest.php
index 537839f7bf..31cd02cc4d 100644
--- a/core/modules/views/src/Tests/Plugin/StyleTableTest.php
+++ b/core/modules/views/src/Tests/Plugin/StyleTableTest.php
@@ -113,7 +113,7 @@ public function testNumericFieldVisible() {
     // Adds a new datapoint in the views_test_data table to have a person with
     // an age of zero.
     $data_set = $this->dataSet();
-    $query = db_insert('views_test_data')
+    $query = \Drupal::database()->insert('views_test_data')
       ->fields(array_keys($data_set[0]));
     $query->values([
       'name' => 'James McCartney',
diff --git a/core/modules/views/src/Tests/ViewKernelTestBase.php b/core/modules/views/src/Tests/ViewKernelTestBase.php
index b39bc7473a..3bd178f1a0 100644
--- a/core/modules/views/src/Tests/ViewKernelTestBase.php
+++ b/core/modules/views/src/Tests/ViewKernelTestBase.php
@@ -71,7 +71,7 @@ protected function setUpFixtures() {
 
     // Load the test dataset.
     $data_set = $this->dataSet();
-    $query = db_insert('views_test_data')
+    $query = \Drupal::database()->insert('views_test_data')
       ->fields(array_keys($data_set[0]));
     foreach ($data_set as $record) {
       $query->values($record);
diff --git a/core/modules/views/src/Tests/ViewTestBase.php b/core/modules/views/src/Tests/ViewTestBase.php
index 720d528cd3..2a1da8fe66 100644
--- a/core/modules/views/src/Tests/ViewTestBase.php
+++ b/core/modules/views/src/Tests/ViewTestBase.php
@@ -52,7 +52,7 @@ protected function enableViewsTestModule() {
 
     // Load the test dataset.
     $data_set = $this->dataSet();
-    $query = db_insert('views_test_data')
+    $query = \Drupal::database()->insert('views_test_data')
       ->fields(array_keys($data_set[0]));
     foreach ($data_set as $record) {
       $query->values($record);
diff --git a/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php b/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php
index 9f6066eff3..85cfed72d8 100644
--- a/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php
+++ b/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php
@@ -89,7 +89,7 @@ public function testTimeResultCaching() {
       'age' => 29,
       'job' => 'Banjo',
     ];
-    db_insert('views_test_data')->fields($record)->execute();
+    \Drupal::database()->insert('views_test_data')->fields($record)->execute();
 
     // The result should be the same as before, because of the caching. (Note
     // that views_test_data records don't have associated cache tags, and hence
@@ -243,7 +243,7 @@ public function testNoneResultCaching() {
       'age' => 29,
       'job' => 'Banjo',
     ];
-    db_insert('views_test_data')->fields($record)->execute();
+    \Drupal::database()->insert('views_test_data')->fields($record)->execute();
 
     // The Result changes, because the view is not cached.
     $view = Views::getView('test_cache');
diff --git a/core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php b/core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php
index 0aecc72b8f..01581fcc92 100644
--- a/core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php
@@ -30,7 +30,7 @@ protected function read($name) {
   }
 
   protected function insert($name, $data) {
-    db_insert('config')->fields(['name' => $name, 'data' => $data])->execute();
+    \Drupal::database()->insert('config')->fields(['name' => $name, 'data' => $data])->execute();
   }
 
   protected function update($name, $data) {
diff --git a/core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php b/core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php
index 53a87b7dbf..e063572c52 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php
@@ -68,7 +68,7 @@ public function testConcatWsFields() {
    * Tests escaping of LIKE wildcards.
    */
   public function testLikeEscape() {
-    db_insert('test')
+    \Drupal::database()->insert('test')
       ->fields([
         'name' => 'Ring_',
       ])
@@ -94,7 +94,7 @@ public function testLikeEscape() {
    * Tests a LIKE query containing a backslash.
    */
   public function testLikeBackslash() {
-    db_insert('test')
+    \Drupal::database()->insert('test')
       ->fields(['name'])
       ->values([
         'name' => 'abcde\f',
diff --git a/core/tests/Drupal/KernelTests/Core/Database/CaseSensitivityTest.php b/core/tests/Drupal/KernelTests/Core/Database/CaseSensitivityTest.php
index c3e766fab4..2bad4654b7 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/CaseSensitivityTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/CaseSensitivityTest.php
@@ -14,7 +14,7 @@ class CaseSensitivityTest extends DatabaseTestBase {
   public function testCaseSensitiveInsert() {
     $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchField();
 
-    db_insert('test')
+    \Drupal::database()->insert('test')
       ->fields([
         'name' => 'john', // <- A record already exists with name 'John'.
         'age' => 2,
diff --git a/core/tests/Drupal/KernelTests/Core/Database/DatabaseTestBase.php b/core/tests/Drupal/KernelTests/Core/Database/DatabaseTestBase.php
index 6fcfaa44ad..c997f8bcfc 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/DatabaseTestBase.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/DatabaseTestBase.php
@@ -35,7 +35,7 @@ protected function setUp() {
    * Sets up tables for NULL handling.
    */
   public function ensureSampleDataNull() {
-    db_insert('test_null')
+    \Drupal::database()->insert('test_null')
       ->fields(['name', 'age'])
       ->values([
       'name' => 'Kermit',
@@ -57,7 +57,7 @@ public function ensureSampleDataNull() {
    */
   public static function addSampleData() {
     // We need the IDs, so we can't use a multi-insert here.
-    $john = db_insert('test')
+    $john = \Drupal::database()->insert('test')
       ->fields([
         'name' => 'John',
         'age' => 25,
@@ -65,7 +65,7 @@ public static function addSampleData() {
       ])
       ->execute();
 
-    $george = db_insert('test')
+    $george = \Drupal::database()->insert('test')
       ->fields([
         'name' => 'George',
         'age' => 27,
@@ -73,7 +73,7 @@ public static function addSampleData() {
       ])
       ->execute();
 
-    db_insert('test')
+    \Drupal::database()->insert('test')
       ->fields([
         'name' => 'Ringo',
         'age' => 28,
@@ -81,7 +81,7 @@ public static function addSampleData() {
       ])
       ->execute();
 
-    $paul = db_insert('test')
+    $paul = \Drupal::database()->insert('test')
       ->fields([
         'name' => 'Paul',
         'age' => 26,
@@ -89,7 +89,7 @@ public static function addSampleData() {
       ])
       ->execute();
 
-    db_insert('test_people')
+    \Drupal::database()->insert('test_people')
       ->fields([
         'name' => 'Meredith',
         'age' => 30,
@@ -97,7 +97,7 @@ public static function addSampleData() {
       ])
       ->execute();
 
-    db_insert('test_task')
+    \Drupal::database()->insert('test_task')
       ->fields(['pid', 'task', 'priority'])
       ->values([
         'pid' => $john,
@@ -136,7 +136,7 @@ public static function addSampleData() {
       ])
       ->execute();
 
-    db_insert('test_special_columns')
+    \Drupal::database()->insert('test_special_columns')
       ->fields([
         'id' => 1,
         'offset' => 'Offset value 1',
diff --git a/core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php b/core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php
index 5b6c03e927..1272fdb503 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php
@@ -15,7 +15,7 @@ class InsertDefaultsTest extends DatabaseTestBase {
    * Tests that we can run a query that uses default values for everything.
    */
   public function testDefaultInsert() {
-    $query = db_insert('test')->useDefaults(['job']);
+    $query = \Drupal::database()->insert('test')->useDefaults(['job']);
     $id = $query->execute();
 
     $schema = drupal_get_module_schema('database_test', 'test');
@@ -31,7 +31,7 @@ public function testDefaultEmptyInsert() {
     $num_records_before = (int) db_query('SELECT COUNT(*) FROM {test}')->fetchField();
 
     try {
-      db_insert('test')->execute();
+      \Drupal::database()->insert('test')->execute();
       // This is only executed if no exception has been thrown.
       $this->fail('Expected exception NoFieldsException has not been thrown.');
     }
@@ -47,7 +47,7 @@ public function testDefaultEmptyInsert() {
    * Tests that we can insert fields with values and defaults in the same query.
    */
   public function testDefaultInsertWithFields() {
-    $query = db_insert('test')
+    $query = \Drupal::database()->insert('test')
       ->fields(['name' => 'Bob'])
       ->useDefaults(['job']);
     $id = $query->execute();
diff --git a/core/tests/Drupal/KernelTests/Core/Database/InsertLobTest.php b/core/tests/Drupal/KernelTests/Core/Database/InsertLobTest.php
index e7a3107a87..6ca6f3b2fe 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/InsertLobTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/InsertLobTest.php
@@ -15,7 +15,7 @@ class InsertLobTest extends DatabaseTestBase {
   public function testInsertOneBlob() {
     $data = "This is\000a test.";
     $this->assertTrue(strlen($data) === 15, 'Test data contains a NULL.');
-    $id = db_insert('test_one_blob')
+    $id = \Drupal::database()->insert('test_one_blob')
       ->fields(['blob1' => $data])
       ->execute();
     $r = db_query('SELECT * FROM {test_one_blob} WHERE id = :id', [':id' => $id])->fetchAssoc();
@@ -26,7 +26,7 @@ public function testInsertOneBlob() {
    * Tests that we can insert multiple blob fields in the same query.
    */
   public function testInsertMultipleBlob() {
-    $id = db_insert('test_two_blobs')
+    $id = \Drupal::database()->insert('test_two_blobs')
       ->fields([
         'blob1' => 'This is',
         'blob2' => 'a test',
diff --git a/core/tests/Drupal/KernelTests/Core/Database/InsertTest.php b/core/tests/Drupal/KernelTests/Core/Database/InsertTest.php
index 1c2c21df82..731c930f2d 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/InsertTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/InsertTest.php
@@ -15,7 +15,7 @@ class InsertTest extends DatabaseTestBase {
   public function testSimpleInsert() {
     $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchField();
 
-    $query = db_insert('test');
+    $query = \Drupal::database()->insert('test');
     $query->fields([
       'name' => 'Yoko',
       'age' => '29',
@@ -37,7 +37,7 @@ public function testSimpleInsert() {
   public function testMultiInsert() {
     $num_records_before = (int) db_query('SELECT COUNT(*) FROM {test}')->fetchField();
 
-    $query = db_insert('test');
+    $query = \Drupal::database()->insert('test');
     $query->fields([
       'name' => 'Larry',
       'age' => '30',
@@ -76,7 +76,7 @@ public function testMultiInsert() {
   public function testRepeatedInsert() {
     $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchField();
 
-    $query = db_insert('test');
+    $query = \Drupal::database()->insert('test');
 
     $query->fields([
       'name' => 'Larry',
@@ -118,7 +118,7 @@ public function testRepeatedInsert() {
   public function testInsertFieldOnlyDefinition() {
     // This is useful for importers, when we want to create a query and define
     // its fields once, then loop over a multi-insert execution.
-    db_insert('test')
+    \Drupal::database()->insert('test')
       ->fields(['name', 'age'])
       ->values(['Larry', '30'])
       ->values(['Curly', '31'])
@@ -136,7 +136,7 @@ public function testInsertFieldOnlyDefinition() {
    * Tests that inserts return the proper auto-increment ID.
    */
   public function testInsertLastInsertID() {
-    $id = db_insert('test')
+    $id = \Drupal::database()->insert('test')
       ->fields([
         'name' => 'Larry',
         'age' => '30',
@@ -164,7 +164,7 @@ public function testInsertSelectFields() {
     // SELECT tp.age AS age, tp.name AS name, tp.job AS job
     // FROM test_people tp
     // WHERE tp.name = 'Meredith'
-    db_insert('test')
+    \Drupal::database()->insert('test')
       ->from($query)
       ->execute();
 
@@ -185,7 +185,7 @@ public function testInsertSelectAll() {
     // SELECT *
     // FROM test_people tp
     // WHERE tp.name = 'Meredith'
-    db_insert('test_people_copy')
+    \Drupal::database()->insert('test_people_copy')
       ->from($query)
       ->execute();
 
@@ -197,7 +197,7 @@ public function testInsertSelectAll() {
    * Tests that we can INSERT INTO a special named column.
    */
   public function testSpecialColumnInsert() {
-    $id = db_insert('test_special_columns')
+    $id = \Drupal::database()->insert('test_special_columns')
       ->fields([
         'id' => 2,
         'offset' => 'Offset value 2',
diff --git a/core/tests/Drupal/KernelTests/Core/Database/InvalidDataTest.php b/core/tests/Drupal/KernelTests/Core/Database/InvalidDataTest.php
index 7b08b40475..9e0ac944a8 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/InvalidDataTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/InvalidDataTest.php
@@ -17,7 +17,7 @@ class InvalidDataTest extends DatabaseTestBase {
   public function testInsertDuplicateData() {
     // Try to insert multiple records where at least one has bad data.
     try {
-      db_insert('test')
+      \Drupal::database()->insert('test')
         ->fields(['name', 'age', 'job'])
         ->values([
           'name' => 'Elvis',
diff --git a/core/tests/Drupal/KernelTests/Core/Database/QueryTest.php b/core/tests/Drupal/KernelTests/Core/Database/QueryTest.php
index 04ba8ad135..cec7e4510e 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/QueryTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/QueryTest.php
@@ -94,7 +94,7 @@ public function testConditionOperatorArgumentsSQLInjection() {
     // Attempt SQLi via union query with no unsafe characters.
     $this->enableModules(['user']);
     $this->installEntitySchema('user');
-    db_insert('test')
+    \Drupal::database()->insert('test')
       ->fields(['name' => '123456'])
       ->execute();
     $injection = "= 1 UNION ALL SELECT password FROM user WHERE uid =";
@@ -111,7 +111,7 @@ public function testConditionOperatorArgumentsSQLInjection() {
     }
 
     // Attempt SQLi via union query - uppercase tablename.
-    db_insert('TEST_UPPERCASE')
+    \Drupal::database()->insert('TEST_UPPERCASE')
       ->fields(['name' => 'secrets'])
       ->execute();
     $injection = "IS NOT NULL) UNION ALL SELECT name FROM {TEST_UPPERCASE} -- ";
diff --git a/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php b/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php
index db4c7deda6..905f491d30 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php
@@ -22,7 +22,7 @@ class RegressionTest extends DatabaseTestBase {
   public function testRegression_310447() {
     // That's a 255 character UTF-8 string.
     $job = str_repeat("é", 255);
-    db_insert('test')
+    \Drupal::database()->insert('test')
       ->fields([
         'name' => $this->randomMachineName(),
         'age' => 20,
diff --git a/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
index e239098715..5e43a22436 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
@@ -403,7 +403,7 @@ public function testIndexLength() {
    */
   public function tryInsert($table = 'test_table') {
     try {
-      db_insert($table)
+      \Drupal::database()->insert($table)
         ->fields(['id' => mt_rand(10, 20)])
         ->execute();
       return TRUE;
@@ -479,7 +479,7 @@ public function testUnsignedColumns() {
    */
   public function tryUnsignedInsert($table_name, $column_name) {
     try {
-      db_insert($table_name)
+      \Drupal::database()->insert($table_name)
         ->fields([$column_name => -1])
         ->execute();
       return TRUE;
@@ -607,7 +607,7 @@ protected function assertFieldAdditionRemoval($field_spec) {
 
     // Insert some rows to the table to test the handling of initial values.
     for ($i = 0; $i < 3; $i++) {
-      db_insert($table_name)
+      \Drupal::database()->insert($table_name)
         ->useDefaults(['serial_column'])
         ->execute();
     }
@@ -660,7 +660,7 @@ protected function assertFieldCharacteristics($table_name, $field_name, $field_s
     // Check that the default value has been registered.
     if (isset($field_spec['default'])) {
       // Try inserting a row, and check the resulting value of the new column.
-      $id = db_insert($table_name)
+      $id = \Drupal::database()->insert($table_name)
         ->useDefaults(['serial_column'])
         ->execute();
       $field_value = db_select($table_name)
@@ -744,7 +744,7 @@ protected function assertFieldChange($old_spec, $new_spec, $test_data = NULL) {
     db_truncate($table_name)->execute();
 
     if ($test_data) {
-      $id = db_insert($table_name)
+      $id = \Drupal::database()->insert($table_name)
         ->fields(['test_field'], [$test_data])
         ->execute();
     }
diff --git a/core/tests/Drupal/KernelTests/Core/Database/SelectSubqueryTest.php b/core/tests/Drupal/KernelTests/Core/Database/SelectSubqueryTest.php
index 58a66289e2..298b0e1d42 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/SelectSubqueryTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/SelectSubqueryTest.php
@@ -209,7 +209,7 @@ public function testJoinSubquerySelect() {
    */
   public function testExistsSubquerySelect() {
     // Put George into {test_people}.
-    db_insert('test_people')
+    \Drupal::database()->insert('test_people')
       ->fields([
         'name' => 'George',
         'age' => 27,
@@ -239,7 +239,7 @@ public function testExistsSubquerySelect() {
    */
   public function testNotExistsSubquerySelect() {
     // Put George into {test_people}.
-    db_insert('test_people')
+    \Drupal::database()->insert('test_people')
       ->fields([
         'name' => 'George',
         'age' => 27,
diff --git a/core/tests/Drupal/KernelTests/Core/Database/SelectTest.php b/core/tests/Drupal/KernelTests/Core/Database/SelectTest.php
index 0d332d0314..7bb8a7ab1c 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/SelectTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/SelectTest.php
@@ -401,7 +401,7 @@ public function testRandomOrder() {
     // after shuffling it (in other words, nearly impossible).
     $number_of_items = 52;
     while (db_query("SELECT MAX(id) FROM {test}")->fetchField() < $number_of_items) {
-      db_insert('test')->fields(['name' => $this->randomMachineName()])->execute();
+      \Drupal::database()->insert('test')->fields(['name' => $this->randomMachineName()])->execute();
     }
 
     // First select the items in order and make sure we get an ordered list.
diff --git a/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php b/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php
index a07045dd53..098e5424b4 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php
@@ -57,7 +57,7 @@ protected function transactionOuterLayer($suffix, $rollback = FALSE, $ddl_statem
     $txn = db_transaction();
 
     // Insert a single row into the testing table.
-    db_insert('test')
+    \Drupal::database()->insert('test')
       ->fields([
         'name' => 'David' . $suffix,
         'age' => '24',
@@ -107,7 +107,7 @@ protected function transactionInnerLayer($suffix, $rollback = FALSE, $ddl_statem
     $this->assertTrue($depth < $depth2, 'Transaction depth is has increased with new transaction.');
 
     // Insert a single row into the testing table.
-    db_insert('test')
+    \Drupal::database()->insert('test')
       ->fields([
         'name' => 'Daniel' . $suffix,
         'age' => '19',
@@ -310,7 +310,7 @@ public function testTransactionWithDdlStatement() {
    * Inserts a single row into the testing table.
    */
   protected function insertRow($name) {
-    db_insert('test')
+    \Drupal::database()->insert('test')
       ->fields([
         'name' => $name,
       ])
diff --git a/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php b/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php
index 501f918314..4cf76ea52a 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php
@@ -15,7 +15,7 @@ class UpdateLobTest extends DatabaseTestBase {
   public function testUpdateOneBlob() {
     $data = "This is\000a test.";
     $this->assertTrue(strlen($data) === 15, 'Test data contains a NULL.');
-    $id = db_insert('test_one_blob')
+    $id = \Drupal::database()->insert('test_one_blob')
       ->fields(['blob1' => $data])
       ->execute();
 
@@ -33,7 +33,7 @@ public function testUpdateOneBlob() {
    * Confirms that we can update two blob columns in the same table.
    */
   public function testUpdateMultipleBlob() {
-    $id = db_insert('test_two_blobs')
+    $id = \Drupal::database()->insert('test_two_blobs')
       ->fields([
         'blob1' => 'This is',
         'blob2' => 'a test',
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php b/core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php
index 884ee89956..270c1b2552 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php
@@ -124,7 +124,7 @@ public function testFieldLoad() {
 
     // Generate values and insert them directly in the storage tables.
     $values = [];
-    $query = db_insert($this->revisionTable)->fields($columns);
+    $query = \Drupal::database()->insert($this->revisionTable)->fields($columns);
     foreach ($revision_ids as $revision_id) {
       // Put one value too many.
       for ($delta = 0; $delta <= $this->fieldCardinality; $delta++) {
@@ -134,7 +134,7 @@ public function testFieldLoad() {
       }
       $query->execute();
     }
-    $query = db_insert($this->table)->fields($columns);
+    $query = \Drupal::database()->insert($this->table)->fields($columns);
     foreach ($values[$revision_id] as $delta => $value) {
       $query->values([$bundle, 0, $entity->id(), $revision_id, $delta, $entity->language()->getId(), $value]);
     }
@@ -168,8 +168,8 @@ public function testFieldLoad() {
     // loaded.
     $unavailable_langcode = 'xx';
     $values = [$bundle, 0, $entity->id(), $entity->getRevisionId(), 0, $unavailable_langcode, mt_rand(1, 127)];
-    db_insert($this->table)->fields($columns)->values($values)->execute();
-    db_insert($this->revisionTable)->fields($columns)->values($values)->execute();
+    \Drupal::database()->insert($this->table)->fields($columns)->values($values)->execute();
+    \Drupal::database()->insert($this->revisionTable)->fields($columns)->values($values)->execute();
     $entity = $storage->load($entity->id());
     $this->assertFalse(array_key_exists($unavailable_langcode, $entity->{$this->fieldName}));
   }
