Reputation: 512
I was going through the different commands in SQL and I came across ALTER
command which is referred as DDL (Data Definition Language). We can alter the column and values in it, so we can manipulate the data with this command so why does alter command is not referred as DML (Data Manipulation Language).
I have googled and I cannot come across some good explanation, so please help me with this.
Upvotes: 5
Views: 8017
Reputation: 172378
ALTER
command is used to alter the structure of the database. And this is what DDL does, i.e. DDL statements are used to define the database structure or schema.
Whereas DML statement is used to manage data within schema objects.
Upvotes: 7
Reputation: 71
The ALTER command can be both DDL and DML. I have known ALTER to be DDL over the past just like the majority of those who have responded to this. However, with MySQL 5.7.x you will see that soon after initializing the database with mysqld --initialize --console
a default root user account and its corresponding password is created. You can access your database with this newly created root user account BUT there is absolutely nothing that you can do after logging in. The only SQL statement allowed at this stage is the ALTER statement. This is used to change the default password generated during initialization. The syntax is ALTER USER 'root'@'localhost' IDENTITIED BY 'new_password';
. This is the only statement that the database accepts. This modifies/updates/manipulates the data (password) in the users table. In this regard I have concluded that the ALTER statement can be both DDL and DML
Upvotes: 0
Reputation: 61865
DDL - alter the schema.
This including creating tables, renaming columns, dropping views, etc. Such statements are DDL even though such might create (default value), alter (by conversion), or even lose (removed column) data as part of the process. Basically, any CREATE/DROP/ALTER
command is DDL.
DML - alter the information/data within the schema; without updating the schema.
This includes DELETE
and UPDATE
statements.
Sometimes DDL and DML must be used together to correctly migrate a schema; but they are two distinct categories of SQL commands, and DML never causes the schema to be changed.
Upvotes: 2
Reputation: 15118
The "data" is the data in the tables defined by the user via DDL. The "metadata" is the data in the tables pre-defined by the DBMS that describe the tables (themselves and those defined by the user). So DML manipulates data in user tables or (usually only) reads metadata from system tables while DDL defines (CREATEs, ALTERs, DROPs) user tables and as a side effect updates metadata in system tables.
Upvotes: 0
Reputation: 3137
Cause ALTER command is not manipulating the data. It is used to change a definition of o column or table or other DB objects.
See http://www.w3schools.com/sql/sql_alter.asp
Upvotes: 1