diff --git a/core/includes/database.inc b/core/includes/database.inc
index ff03885..044a09b 100644
--- a/core/includes/database.inc
+++ b/core/includes/database.inc
@@ -26,7 +26,7 @@
  * instead.
  *
  * Do not use this function for INSERT, UPDATE, or DELETE queries. Those should
- * be handled via db_insert(), db_update() and db_delete() respectively.
+ * be handled via \Drupal::database()->insert(), db_update() and db_delete() respectively.
  *
  * @param string|\Drupal\Core\Database\StatementInterface $query
  *   The prepared statement query to run. Although it will accept both named and
diff --git a/core/lib/Drupal/Core/Database/database.api.php b/core/lib/Drupal/Core/Database/database.api.php
index 07e4343..1a767b6 100644
--- a/core/lib/Drupal/Core/Database/database.api.php
+++ b/core/lib/Drupal/Core/Database/database.api.php
@@ -124,11 +124,11 @@
  * @section_insert INSERT, UPDATE, and DELETE queries
  * INSERT, UPDATE, and DELETE queries need special care in order to behave
  * consistently across databases; you should never use db_query() to run
- * an INSERT, UPDATE, or DELETE query. Instead, use functions db_insert(),
+ * an INSERT, UPDATE, or DELETE query. Instead, use functions \Drupal::database()->insert(),
  * db_update(), and db_delete() to obtain a base query on your table, and then
  * add dynamic conditions (as illustrated in @ref sec_dynamic above).
  *
- * As a note, db_insert() and similar functions are wrappers on connection
+ * As a note, \Drupal::database()->insert() and similar functions are wrappers on connection
  * object methods. In most classes, you should use dependency injection and the
  * database connection object instead of these wrappers; See @ref sec_connection
  * below for details.
@@ -140,7 +140,7 @@
  * You can execute it via:
  * @code
  * $fields = array('id' => 1, 'uid' => 2, 'path' => 'path', 'name' => 'Name');
- * db_insert('example')
+ * \Drupal::database()->insert('example')
  *   ->fields($fields)
  *   ->execute();
  * @endcode
@@ -162,7 +162,7 @@
  *   $txn = db_transaction();
  *
  *   try {
- *     $id = db_insert('example')
+ *     $id = \Drupal::database()->insert('example')
  *       ->fields(array(
  *         'field1' => 'mystring',
  *         'field2' => 5,
diff --git a/core/lib/Drupal/Core/Entity/entity.api.php b/core/lib/Drupal/Core/Entity/entity.api.php
index 5ee5af6..d7e2f80 100644
--- a/core/lib/Drupal/Core/Entity/entity.api.php
+++ b/core/lib/Drupal/Core/Entity/entity.api.php
@@ -938,7 +938,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(array(
       'type' => $entity->getEntityTypeId(),
       'id' => $entity->id(),
@@ -947,7 +947,6 @@ function hook_entity_insert(Drupal\Core\Entity\EntityInterface $entity) {
     ))
     ->execute();
 }
-
 /**
  * Respond to creation of a new entity of a particular type.
  *
@@ -962,7 +961,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(array(
       'id' => $entity->id(),
       'created' => REQUEST_TIME,
@@ -970,7 +969,6 @@ function hook_ENTITY_TYPE_insert(Drupal\Core\Entity\EntityInterface $entity) {
     ))
     ->execute();
 }
-
 /**
  * Respond to updates to an entity.
  *
diff --git a/core/modules/contact/tests/drupal-7.contact.database.php b/core/modules/contact/tests/drupal-7.contact.database.php
index 115f83c..a80fc58 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(array(
+\Drupal::database()->insert('contact')->fields(array(
   'category',
   'recipients',
   'reply',
diff --git a/core/modules/file/tests/src/Kernel/UsageTest.php b/core/modules/file/tests/src/Kernel/UsageTest.php
index 8e26015..eba2890 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 {
    */
   function testGetUsage() {
     $file = $this->createFile();
-    db_insert('file_usage')
+    \Drupal::database()->insert('file_usage')
       ->fields(array(
         'fid' => $file->id(),
         'module' => 'testing',
@@ -29,7 +29,7 @@ function testGetUsage() {
         'count' => 1
       ))
       ->execute();
-    db_insert('file_usage')
+    \Drupal::database()->insert('file_usage')
       ->fields(array(
         'fid' => $file->id(),
         'module' => 'testing',
@@ -80,7 +80,7 @@ function testAddUsage() {
   function testRemoveUsage() {
     $file = $this->createFile();
     $file_usage = $this->container->get('file.usage');
-    db_insert('file_usage')
+    \Drupal::database()->insert('file_usage')
       ->fields(array(
         '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 0f48401..ac4007a 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(array(
         'uid' => $account->id(),
         'nid' => $nodes[0]->id(),
         'timestamp' => REQUEST_TIME - 100,
       ))->execute();
 
-    db_insert('history')
+    \Drupal::database()->insert('history')
       ->fields(array(
         '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 85196ad..39ad5e8 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.api.php b/core/modules/node/node.api.php
index a4937f7..b96e010 100644
--- a/core/modules/node/node.api.php
+++ b/core/modules/node/node.api.php
@@ -51,7 +51,7 @@
  *   'grant_update' => 0,
  *   'grant_delete' => 0,
  * );
- * db_insert('node_access')->fields($record)->execute();
+ * \Drupal::database()->insert('node_access')->fields($record)->execute();
  * @endcode
  * And then in its hook_node_grants() implementation, it would need to return:
  * @code
diff --git a/core/modules/node/node.install b/core/modules/node/node.install
index 0582459..494faab 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(array(
       'nid' => 0,
       'gid' => 0,
diff --git a/core/modules/node/src/Tests/NodeAccessGrantsCacheContextTest.php b/core/modules/node/src/Tests/NodeAccessGrantsCacheContextTest.php
index 5932108..19815e1 100644
--- a/core/modules/node/src/Tests/NodeAccessGrantsCacheContextTest.php
+++ b/core/modules/node/src/Tests/NodeAccessGrantsCacheContextTest.php
@@ -93,7 +93,6 @@ public function testCacheContext() {
       'grant_delete' => 0,
     );
     db_insert('node_access')->fields($record)->execute();
-
     // Put user accessUser (uid 0) in the realm.
     \Drupal::state()->set('node_access_test.no_access_uid', 0);
     drupal_static_reset('node_access_view_all_nodes');
diff --git a/core/modules/node/src/Tests/NodeQueryAlterTest.php b/core/modules/node/src/Tests/NodeQueryAlterTest.php
index 022625b..2c5582a 100644
--- a/core/modules/node/src/Tests/NodeQueryAlterTest.php
+++ b/core/modules/node/src/Tests/NodeQueryAlterTest.php
@@ -151,7 +151,7 @@ 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/path/path.api.php b/core/modules/path/path.api.php
index 04e1fb3..15b639f 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(array(
       'alias' => $path['alias'],
       'pid' => $path['pid'],
diff --git a/core/modules/search/search.module b/core/modules/search/search.module
index c36aa44..b690351 100644
--- a/core/modules/search/search.module
+++ b/core/modules/search/search.module
@@ -522,7 +522,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(array(
       'sid' => $sid,
       'langcode' => $langcode,
diff --git a/core/modules/search/src/Tests/SearchRankingTest.php b/core/modules/search/src/Tests/SearchRankingTest.php
index 2045233..2d8212f 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(array('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 c9eed3b..a7ded72e 100644
--- a/core/modules/simpletest/simpletest.module
+++ b/core/modules/simpletest/simpletest.module
@@ -137,7 +137,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(array('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 e90fc57..391450c 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(array(
       'data' => $schema['fields']['data']['type'],
     ))
diff --git a/core/modules/tracker/tracker.module b/core/modules/tracker/tracker.module
index 1b2f648..685a19b 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(array(
           '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(array(
           '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(array(
             'uid' => $row['uid'],
diff --git a/core/modules/user/user.api.php b/core/modules/user/user.api.php
index 2f40eb9..4df7d60 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(array(
       '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 9a3f25e..a0ba1da 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(array(
       'name' => 'James McCartney',
diff --git a/core/modules/views/src/Tests/ViewKernelTestBase.php b/core/modules/views/src/Tests/ViewKernelTestBase.php
index 3a5df34..9f91743 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 6ce3494..0e26897 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 31805d8..753dc3f 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 @@ 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/scripts/dump-database-d6.sh b/core/scripts/dump-database-d6.sh
index d0a89d7..4679a19 100644
--- a/core/scripts/dump-database-d6.sh
+++ b/core/scripts/dump-database-d6.sh
@@ -90,7 +90,7 @@
 
   // Dump the values if there are some.
   if ($insert) {
-    $output .= "db_insert('". $table . "')->fields(". drupal_var_export(array_keys($data['fields'])) .")\n";
+    $output .= "\Drupal::database()->insert('". $table . "')->fields(". drupal_var_export(array_keys($data['fields'])) .")\n";
     $output .= $insert;
     $output .= "->execute();\n";
   }
diff --git a/core/scripts/dump-database-d7.sh b/core/scripts/dump-database-d7.sh
index 4689672..033b581 100644
--- a/core/scripts/dump-database-d7.sh
+++ b/core/scripts/dump-database-d7.sh
@@ -80,7 +80,7 @@
 
   // Dump the values if there are some.
   if ($insert) {
-    $output .= "db_insert('". $table . "')->fields(". drupal_var_export(array_keys($data['fields'])) .")\n";
+    $output .= "\Drupal::database()->insert('". $table . "')->fields(". drupal_var_export(array_keys($data['fields'])) .")\n";
     $output .= $insert;
     $output .= "->execute();\n";
   }
diff --git a/core/scripts/generate-d7-content.sh b/core/scripts/generate-d7-content.sh
index 8b591f4..4836b7c 100644
--- a/core/scripts/generate-d7-content.sh
+++ b/core/scripts/generate-d7-content.sh
@@ -45,7 +45,7 @@
 drupal_cron_run();
 
 // Create six users
-$query = db_insert('users')->fields(array('uid', 'name', 'pass', 'mail', 'status', 'created', 'access'));
+$query = \Drupal::database()->insert('users')->fields(array('uid', 'name', 'pass', 'mail', 'status', 'created', 'access'));
 for ($i = 0; $i < 6; $i++) {
   $name = "test user $i";
   $pass = md5("test PassW0rd $i !(.)");
diff --git a/core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php b/core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php
index 6f09a82..fcf7494 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(array('name' => $name, 'data' => $data))->execute();
+    \Drupal::database()->insert('config')->fields(array('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 eaf50e5..972b732 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php
@@ -68,7 +68,7 @@ function testConcatWsFields() {
    * Tests escaping of LIKE wildcards.
    */
   function testLikeEscape() {
-    db_insert('test')
+    \Drupal::database()->insert('test')
       ->fields(array(
         'name' => 'Ring_',
       ))
@@ -94,7 +94,7 @@ function testLikeEscape() {
    * Tests a LIKE query containing a backslash.
    */
   function testLikeBackslash() {
-    db_insert('test')
+    \Drupal::database()->insert('test')
       ->fields(array('name'))
       ->values(array(
         'name' => 'abcde\f',
diff --git a/core/tests/Drupal/KernelTests/Core/Database/CaseSensitivityTest.php b/core/tests/Drupal/KernelTests/Core/Database/CaseSensitivityTest.php
index 35fdb4d..0e7f92c 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 {
   function testCaseSensitiveInsert() {
     $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchField();
 
-    db_insert('test')
+    \Drupal::database()->insert('test')
       ->fields(array(
         '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 f8c8c3d..6de4953 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.
    */
   function ensureSampleDataNull() {
-    db_insert('test_null')
+    \Drupal::database()->insert('test_null')
       ->fields(array('name', 'age'))
       ->values(array(
       'name' => 'Kermit',
@@ -57,7 +57,7 @@ function ensureSampleDataNull() {
    */
   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(array(
         'name' => 'John',
         'age' => 25,
@@ -65,7 +65,7 @@ static function addSampleData() {
       ))
       ->execute();
 
-    $george = db_insert('test')
+    $george = \Drupal::database()->insert('test')
       ->fields(array(
         'name' => 'George',
         'age' => 27,
@@ -73,7 +73,7 @@ static function addSampleData() {
       ))
       ->execute();
 
-    db_insert('test')
+    \Drupal::database()->insert('test')
       ->fields(array(
         'name' => 'Ringo',
         'age' => 28,
@@ -81,7 +81,7 @@ static function addSampleData() {
       ))
       ->execute();
 
-    $paul = db_insert('test')
+    $paul = \Drupal::database()->insert('test')
       ->fields(array(
         'name' => 'Paul',
         'age' => 26,
@@ -89,7 +89,7 @@ static function addSampleData() {
       ))
       ->execute();
 
-    db_insert('test_people')
+    \Drupal::database()->insert('test_people')
       ->fields(array(
         'name' => 'Meredith',
         'age' => 30,
@@ -97,7 +97,7 @@ static function addSampleData() {
       ))
       ->execute();
 
-    db_insert('test_task')
+    \Drupal::database()->insert('test_task')
       ->fields(array('pid', 'task', 'priority'))
       ->values(array(
         'pid' => $john,
@@ -136,7 +136,7 @@ static function addSampleData() {
       ))
       ->execute();
 
-    db_insert('test_special_columns')
+    \Drupal::database()->insert('test_special_columns')
       ->fields(array(
         '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 6e0363a..629571c 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.
    */
   function testDefaultInsert() {
-    $query = db_insert('test')->useDefaults(array('job'));
+    $query = \Drupal::database()->insert('test')->useDefaults(array('job'));
     $id = $query->execute();
 
     $schema = drupal_get_module_schema('database_test', 'test');
@@ -31,7 +31,7 @@ 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 @@ function testDefaultEmptyInsert() {
    * Tests that we can insert fields with values and defaults in the same query.
    */
   function testDefaultInsertWithFields() {
-    $query = db_insert('test')
+    $query = \Drupal::database()->insert('test')
       ->fields(array('name' => 'Bob'))
       ->useDefaults(array('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 cb41dc0..d07628e 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 {
   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(array('blob1' => $data))
       ->execute();
     $r = db_query('SELECT * FROM {test_one_blob} WHERE id = :id', array(':id' => $id))->fetchAssoc();
@@ -26,7 +26,7 @@ function testInsertOneBlob() {
    * Tests that we can insert multiple blob fields in the same query.
    */
   function testInsertMultipleBlob() {
-    $id = db_insert('test_two_blobs')
+    $id = \Drupal::database()->insert('test_two_blobs')
       ->fields(array(
         '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 d703f9d..a11ecd8 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 {
   function testSimpleInsert() {
     $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchField();
 
-    $query = db_insert('test');
+    $query = \Drupal::database()->insert('test');
     $query->fields(array(
       'name' => 'Yoko',
       'age' => '29',
@@ -37,7 +37,7 @@ function testSimpleInsert() {
   function testMultiInsert() {
     $num_records_before = (int) db_query('SELECT COUNT(*) FROM {test}')->fetchField();
 
-    $query = db_insert('test');
+    $query = \Drupal::database()->insert('test');
     $query->fields(array(
       'name' => 'Larry',
       'age' => '30',
@@ -76,7 +76,7 @@ function testMultiInsert() {
   function testRepeatedInsert() {
     $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchField();
 
-    $query = db_insert('test');
+    $query = \Drupal::database()->insert('test');
 
     $query->fields(array(
       'name' => 'Larry',
@@ -118,7 +118,7 @@ function testRepeatedInsert() {
   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(array('name', 'age'))
       ->values(array('Larry', '30'))
       ->values(array('Curly', '31'))
@@ -136,8 +136,8 @@ function testInsertFieldOnlyDefinition() {
    * Tests that inserts return the proper auto-increment ID.
    */
   function testInsertLastInsertID() {
-    $id = db_insert('test')
-      ->fields(array(
+    $id = \Drupal::database()->insert(('test'));
+    $id ->fields(array(
         'name' => 'Larry',
         'age' => '30',
       ))
@@ -164,7 +164,7 @@ 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 @@ 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 @@ function testInsertSelectAll() {
    * Tests that we can INSERT INTO a special named column.
    */
   function testSpecialColumnInsert() {
-    $id = db_insert('test_special_columns')
+    $id = \Drupal::database()->insert('test_special_columns')
       ->fields(array(
         '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 774a20b..5449138 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 {
   function testInsertDuplicateData() {
     // Try to insert multiple records where at least one has bad data.
     try {
-      db_insert('test')
+      \Drupal::database()->insert('test')
         ->fields(array('name', 'age', 'job'))
         ->values(array(
           'name' => 'Elvis',
diff --git a/core/tests/Drupal/KernelTests/Core/Database/QueryTest.php b/core/tests/Drupal/KernelTests/Core/Database/QueryTest.php
index f84a9c8..7cc0b47 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 e13bcfe..5829fe4 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 {
   function testRegression_310447() {
     // That's a 255 character UTF-8 string.
     $job = str_repeat("é", 255);
-    db_insert('test')
+    \Drupal::database()->insert('test')
       ->fields(array(
         '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 8641fd3..375c237 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
@@ -381,7 +381,7 @@ function testIndexLength() {
    */
   function tryInsert($table = 'test_table') {
     try {
-      db_insert($table)
+      \Drupal::database()->insert($table)
         ->fields(array('id' => mt_rand(10, 20)))
         ->execute();
       return TRUE;
@@ -457,7 +457,7 @@ function testUnsignedColumns() {
    */
   function tryUnsignedInsert($table_name, $column_name) {
     try {
-      db_insert($table_name)
+      \Drupal::database()->insert($table_name)
         ->fields(array($column_name => -1))
         ->execute();
       return TRUE;
@@ -585,7 +585,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(array('serial_column'))
         ->execute();
     }
@@ -638,7 +638,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(array('serial_column'))
         ->execute();
       $field_value = db_select($table_name)
@@ -722,7 +722,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 98849bb..2dc6835 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/SelectSubqueryTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/SelectSubqueryTest.php
@@ -209,7 +209,7 @@ function testJoinSubquerySelect() {
    */
   function testExistsSubquerySelect() {
     // Put George into {test_people}.
-    db_insert('test_people')
+    \Drupal::database()->insert('test_people')
       ->fields(array(
         'name' => 'George',
         'age' => 27,
@@ -239,7 +239,7 @@ function testExistsSubquerySelect() {
    */
   function testNotExistsSubquerySelect() {
     // Put George into {test_people}.
-    db_insert('test_people')
+    \Drupal::database()->insert('test_people')
       ->fields(array(
         '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 b3eef54..a5446fd 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/SelectTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/SelectTest.php
@@ -401,7 +401,7 @@ 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(array('name' => $this->randomMachineName()))->execute();
+      \Drupal::database()->insert('test')->fields(array('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 d060f4d..e06ccbd 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(array(
         '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(array(
         'name' => 'Daniel' . $suffix,
         'age' => '19',
@@ -310,7 +310,7 @@ function testTransactionWithDdlStatement() {
    * Inserts a single row into the testing table.
    */
   protected function insertRow($name) {
-    db_insert('test')
+    \Drupal::database()->insert('test')
       ->fields(array(
         'name' => $name,
       ))
diff --git a/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php b/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php
index 57a1418..93bf051 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 {
   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(array('blob1' => $data))
       ->execute();
 
@@ -33,7 +33,7 @@ function testUpdateOneBlob() {
    * Confirms that we can update two blob columns in the same table.
    */
   function testUpdateMultipleBlob() {
-    $id = db_insert('test_two_blobs')
+    $id = \Drupal::database()->insert('test_two_blobs')
       ->fields(array(
         '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 449f3f2..af6067e 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php
@@ -124,7 +124,7 @@ function testFieldLoad() {
 
     // Generate values and insert them directly in the storage tables.
     $values = array();
-    $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 @@ 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(array($bundle, 0, $entity->id(), $revision_id, $delta, $entity->language()->getId(), $value));
     }
@@ -168,8 +168,8 @@ function testFieldLoad() {
     // loaded.
     $unavailable_langcode = 'xx';
     $values = array($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}));
   }
