DataSunrise Achieves AWS DevOps Competency Status in AWS DevSecOps and Monitoring, Logging, Performance

How Popular Databases Deal with DDL Commands in Transactions

How Popular Databases Deal with DDL Commands in Transactions

Integration of DDL commands into transactions is one of the most powerful features databases provide. But not all the databases are able to rollback DDL changes. Oracle, PostgreSQL, MySQL, MariaDB, DB2, MSSQL, Teradata, Greenplum, Netezza, Redshift, Aurora are the most popular relational databases and this article describes their capability to support DDL commands in transactions.

Transaction is a sequence of commands incorporated into one logical unit. Thus, a transaction is executed as one entity. When an execution of transaction is interrupted, the transaction is not executed at all. Transactions are used to preserve database integrity, singlet execution of all commands transaction includes, means saving integrity constraints and the impossibility to leave the database in a transitional, non-consistent state.

DDL (Data Definition Language) is a family of SQL language elements used to define database structure (including operations with databases, tables, columns, indexes, views, stored procedures, constraints).

To understand what is DDL, it’s important to know that DDL statements play a crucial role in database management systems (DBMS) by allowing users to define and modify the structure of the database. The ability to execute DDL in database management systems is essential for maintaining the integrity and consistency of the data stored within the database. However, the behavior of DDL statements within transactions varies among different DBMS implementations. Understanding how DDL statements behave within transactions in your specific DBMS is crucial for ensuring data integrity and implementing appropriate error handling mechanisms.

Understanding DDL in Database Management Systems

Data Definition Language (DDL) forms a critical component of database management systems, providing the commands necessary to define and modify database structure. Within a DBMS, DDL commands create the framework that holds data and determines how it’s organized, accessed, and maintained.

The most fundamental DDL commands in database management systems include CREATE, ALTER, DROP, TRUNCATE, COMMENT, and RENAME. The CREATE command establishes new database objects like tables, views, indexes, or stored procedures. ALTER modifies existing objects by adding columns, changing data types, or implementing constraints. DROP removes objects entirely from the database schema.

TRUNCATE, while sometimes classified as DML, functions as DDL in most database management systems because it resets table storage and typically cannot be rolled back. COMMENT adds descriptive notes to database objects, enhancing documentation. RENAME changes object identifiers for better clarity or organization.

When executing DDL in database management systems, these commands typically acquire schema locks that prevent concurrent modifications to the same objects. This lock behavior varies between systems—some implement brief locks during metadata changes while others lock objects for the duration of the operation. Understanding these locking behaviors is essential when planning maintenance operations in production environments.

Beyond basic structure modification, DDL in modern database management systems also handles more advanced features like partitioning (dividing tables into smaller, more manageable segments), implementing security policies through GRANT and REVOKE commands, and defining triggers that automatically execute in response to specific events. These capabilities make DDL an exceptionally powerful tool for database architects and administrators.

Our DataSunrise Database Security Suite is purpose-built for protection of relational databases against unauthorized access and data leaks. To perform this task, a powerful system of security policies (the rules) is implemented for database access restriction and dynamic data masking. To employ this functionality, our program should know database metadata state at every moment. Metadata is database schema and system variables’ values sets, which affect query execution and interpreting results. Metadata could be got by sending a series of queries to the database server.

DataSunrise also supports tracking of incremental changes, logs execution results of DDL commands processed by our product. But the really interesting part begins when you need to support metadata changes inside the transaction. Some RDBMSs support DDL commands transactionality, i.e. you can rollback these commands when rollbacking the transaction. Other RDBMSs don’t support DDLs in transactions. DDL commands in such RDBMSs end current transaction implicitly or cause SQL server error.

But the most popular RDBMSs are somewhere in the middle: they do support DDL commands transactionality but not for all commands. Usually, the most global commands used to create and delete file system objects in the database storage, cannot support rollback procedure, thus transactionality is supported for minor commands rollback of which does not cause file system structure changes. Transactions in all RDBMSs are similar only in general. But in practice, each database features unique syntax of transaction control commands and each RDBMS has its own unique transaction control mechanisms. We call this a transaction model of a certain RDBMS.

For correct processing of metadata changes, our program should be able to roll back DDL changes aborted on transaction rollback. It is a quite complex algorithmic task: it requires the support of metadata delta (diff) which corresponds to DDL changes inside current transaction of each connection to the database. Such a delta exists before the transaction is closed and could be rolled back as one piece or in parts (for those RDBMSs which support multi-level transactions or savepoints).

Not let’s take a look at the features the popular databases can offer in the context of transactional DDL.

Oracle Database

Oracle does not support transactional DDL: the transaction is considered as closed when CREATE, DROP, RENAME or ALTER command is executed. If the transaction contains DML commands, the Oracle commits the transaction as a whole and then commits the DDL command as a separate transaction.

PostgreSQL

PostgreSQL supports transactional DDL: all DDL commands except high-caliber operations aimed at creation and deletion of such objects as DATABASE, TABLESPACE, CLUSTER. PostgreSQL supports multi-level transactions on save points level. Unlike standard SQL, PostgreSQL supports homonymous save points. It means that the older points are not available for as long as newer ones exist.

If an error occurs inside a transaction, PostgreSQL rolls back the whole transaction but demands a command to complete the current transaction (COMMIT, ROLLBACK, ABORT) in any case. PostgreSQL starts an implicit transaction in the beginning of multistatement and transforms the transaction into explicit one when there is BEGIN command inside a multistatement (the transaction is considered as started with the beginning of multistatement).

MySQL

MySQL does not support transactional DDL. No transactions available for MyISAM at all. For InnoDB, DDL commands cause implicit commit of the current transaction.

MariaDB

MariaDB inherits its behavior in terms of transactional DDL from MySQL and doesn’t support it.

DB2

DB2 supports multi-level transactions both on nested transaction level and on save points level. Save points are provided with independent namespaces on each nesting level.

Microsoft SQL Server (MS SQL)

The support of multi-level transactions in MS SQL is expressed in the support of save points. In SQL Server, so-called nested transactions serves only as a counter of BEGIN TRANSACTION calls. To confirm transaction it is necessary to call a certain number of COMMIT TRANSACTION, and ROLLBACK command rolls back the whole transaction regardless of nesting level. The first BEGIN TRANSACTION is always regarded as the beginning of the transaction and it enables the full-fledged work with multi-level transactions through save points at the same time. Save points could be used through SAVE TRANSACTION and ROLLBACK TRANSACTION commands.

Teradata

Teradata does not support transactional DDL. DDL could be placed inside a transaction but not more than one command for a transaction and only as the last command in the transaction. Teradata’s behavior similar to Oracle’s in this regard. Thus a DDL could be executed with the execution of transaction or not executed at all with the rollback of the transaction. It means that DDL changes that can exist for a certain time and then be rolled back are not available.

Greenplum

Greenplum’s behavior is similar to PostgreSQL’s.

Netezza

Netezza also originated from PostgreSQL but a long time ago. And features some serious difference in regard to support of transactions. Netezza supports DDL in transactions as well, but it does not provide multi-level transactions support (save points) and it is impossible to begin a transaction not from the beginning of a multistatement, if the multistatement already contains DDL commands.

Amazon Redshift

Similar to PostgreSQL.

Amazon Aurora

Similar to MySQL.

All knowledge about the mentioned features is implemented in DataSunrise Database Security Suite. We always know what your database schema looks like and can provide its perfect protection.

DataSunrise supports all major databases and data warehouses including Oracle or Exadata. It also supports IBM DB2, IBM Netezza, MySQL, MariaDB, Greenplum, Amazon Aurora, Amazon Redshift, Microsoft SQL Server, Azure SQL, Teradata and more. You are welcome to download a free trial if would like to install on your premises. In case you are a cloud user and run your database on Amazon AWS or Microsoft Azure you can get it from AWS market place or Azure market place.

Next

Encryption in Microsoft SQL Server

Encryption in Microsoft SQL Server

Learn More

Need Our Support Team Help?

Our experts will be glad to answer your questions.

Countryx
United States
United Kingdom
France
Germany
Australia
Afghanistan
Islands
Albania
Algeria
American Samoa
Andorra
Angola
Anguilla
Antarctica
Antigua and Barbuda
Argentina
Armenia
Aruba
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belgium
Belize
Benin
Bermuda
Bhutan
Bolivia
Bosnia and Herzegovina
Botswana
Bouvet
Brazil
British Indian Ocean Territory
Brunei Darussalam
Bulgaria
Burkina Faso
Burundi
Cambodia
Cameroon
Canada
Cape Verde
Cayman Islands
Central African Republic
Chad
Chile
China
Christmas Island
Cocos (Keeling) Islands
Colombia
Comoros
Congo, Republic of the
Congo, The Democratic Republic of the
Cook Islands
Costa Rica
Cote D'Ivoire
Croatia
Cuba
Cyprus
Czech Republic
Denmark
Djibouti
Dominica
Dominican Republic
Ecuador
Egypt
El Salvador
Equatorial Guinea
Eritrea
Estonia
Ethiopia
Falkland Islands (Malvinas)
Faroe Islands
Fiji
Finland
French Guiana
French Polynesia
French Southern Territories
Gabon
Gambia
Georgia
Ghana
Gibraltar
Greece
Greenland
Grenada
Guadeloupe
Guam
Guatemala
Guernsey
Guinea
Guinea-Bissau
Guyana
Haiti
Heard Island and Mcdonald Islands
Holy See (Vatican City State)
Honduras
Hong Kong
Hungary
Iceland
India
Indonesia
Iran, Islamic Republic Of
Iraq
Ireland
Isle of Man
Israel
Italy
Jamaica
Japan
Jersey
Jordan
Kazakhstan
Kenya
Kiribati
Korea, Democratic People's Republic of
Korea, Republic of
Kuwait
Kyrgyzstan
Lao People's Democratic Republic
Latvia
Lebanon
Lesotho
Liberia
Libyan Arab Jamahiriya
Liechtenstein
Lithuania
Luxembourg
Macao
Madagascar
Malawi
Malaysia
Maldives
Mali
Malta
Marshall Islands
Martinique
Mauritania
Mauritius
Mayotte
Mexico
Micronesia, Federated States of
Moldova, Republic of
Monaco
Mongolia
Montserrat
Morocco
Mozambique
Myanmar
Namibia
Nauru
Nepal
Netherlands
Netherlands Antilles
New Caledonia
New Zealand
Nicaragua
Niger
Nigeria
Niue
Norfolk Island
North Macedonia, Republic of
Northern Mariana Islands
Norway
Oman
Pakistan
Palau
Palestinian Territory, Occupied
Panama
Papua New Guinea
Paraguay
Peru
Philippines
Pitcairn
Poland
Portugal
Puerto Rico
Qatar
Reunion
Romania
Russian Federation
Rwanda
Saint Helena
Saint Kitts and Nevis
Saint Lucia
Saint Pierre and Miquelon
Saint Vincent and the Grenadines
Samoa
San Marino
Sao Tome and Principe
Saudi Arabia
Senegal
Serbia and Montenegro
Seychelles
Sierra Leone
Singapore
Slovakia
Slovenia
Solomon Islands
Somalia
South Africa
South Georgia and the South Sandwich Islands
Spain
Sri Lanka
Sudan
Suriname
Svalbard and Jan Mayen
Swaziland
Sweden
Switzerland
Syrian Arab Republic
Taiwan, Province of China
Tajikistan
Tanzania, United Republic of
Thailand
Timor-Leste
Togo
Tokelau
Tonga
Trinidad and Tobago
Tunisia
Turkey
Turkmenistan
Turks and Caicos Islands
Tuvalu
Uganda
Ukraine
United Arab Emirates
United States Minor Outlying Islands
Uruguay
Uzbekistan
Vanuatu
Venezuela
Viet Nam
Virgin Islands, British
Virgin Islands, U.S.
Wallis and Futuna
Western Sahara
Yemen
Zambia
Zimbabwe
Choose a topicx
General Information
Sales
Customer Service and Technical Support
Partnership and Alliance Inquiries
General information:
info@datasunrise.com
Customer Service and Technical Support:
support.datasunrise.com
Partnership and Alliance Inquiries:
partner@datasunrise.com