Community Documentation

How to use an SQL snippet

Last updated November 8, 2008. Created by Jody Lynn on December 18, 2005.
Edited by puregin. Log in to edit this page.

An SQL snippet is one more more statements of SQL (Structured Query Language), a relatively standard language for querying databases. An SQL-enabled database engine, such as MySQL or PostgreSQL, will interpret a sequence of statements (queries) and execute them. Statements can request data, insert or update existing data, or alter the structure of the database. Because SQL statements can change (e.g., completely destroy) your database, one must be very careful in executing SQL snippets. Therefore, consider this an advanced topic. You have been warned.

Always backup your database before attempting any kind of SQL administration.

The first step in using an SQL snippet is to ensure that you have access to the database. This will depend on how your Drupal installation is hosted. There are a number of general mechanisms for SQL database access.

  • command line access (e.g., via secure shell - SSH)
  • web-based database administration tools (e.g., phpMyAdmin)
  • Via executing PHP from within Drupal

The precise mechanism for executing an SQL snippet depends on which database you are using, and how the database has been set up. The following sections elaborate on each of these mechanisms.

Page status

No known problems

Log in to edit this page

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here