{"id":158848,"date":"2022-11-11T10:00:00","date_gmt":"2022-11-11T04:30:00","guid":{"rendered":"https:\/\/www.jigsawacademy.com\/?p=158848"},"modified":"2022-11-24T14:22:44","modified_gmt":"2022-11-24T08:52:44","slug":"blogs-business-analytics-dml-commands","status":"publish","type":"post","link":"https:\/\/www.jigsawacademy.com\/blogs\/business-analytics\/dml-commands\/","title":{"rendered":"Elaborate In Detail: DML Commands in SQL | UNext Jigsaw"},"content":{"rendered":"\r\n
In the 21st century, data is the new oil. Every application, software, device, and equipment has some form of data or information that humans can optimize to make it favorable for them. Businesses now understand the importance of data collection and storage and leveraging them to aid their decision-making process. Databases, i.e., information stored digitally in rows and columns, are fundamental to an\u00a0 IT organization. The handling and maintenance of these databases require a steep learning curve for the best results. Therefore, understanding data manipulation commands (DML Commands) is of utmost importance.<\/p>\r\n\r\n\r\n\r\n
Many Relational Database Management Systems (RDBMS) is used to manage databases, such as MS Access, Oracle, Postgres, MySQL, SQLite, SQL Server, etc. Structure Query Language, also known as SQL, is one of the most popular database languages.\u00a0<\/p>\r\n\r\n\r\n\r\n
Here, in this article, we’ll look at the Commands of SQL and its syntax to define the different aspects of various Relational Database Management Systems (RDBMS).\u00a0<\/a><\/p>\r\n The main types of commands present in SQL are:<\/p>\r\n\r\n\r\n\r\n Take a look at some of the commands of SQL queries in this picture:<\/p>\r\n\r\n\r\n\r\n\r\n\r\n Figure<\/strong>: SQL Commands\u00a0source<\/a><\/p>\r\n\r\n\r\n\r\n\r\n\r\n DDL is an abbreviation for Data Definition Language. DDL is used to define the schema or the structure of a database. Here are the main DDL commands of SQL with their syntax.<\/p>\r\n\r\n\r\n\r\n The Create command is used to build new tables, views, and databases in DBMS.<\/p>\r\n\r\n\r\n\r\n Syntax:<\/p>\r\n\r\n\r\n\r\n Example:<\/p>\r\n\r\n\r\n\r\n Executing the Drop command in DDL can remove databases and tables from the RDBMS.<\/p>\r\n\r\n\r\n\r\n Syntax:<\/p>\r\n\r\n\r\n\r\n For example:<\/p>\r\n\r\n\r\n\r\n The Alter command in DDL can change or modify the database structure.<\/p>\r\n\r\n\r\n\r\n Syntax:<\/p>\r\n\r\n\r\n\r\n To add a new row in the table,<\/p>\r\n\r\n\r\n\r\n And to make a change to an existing row in a given database,<\/p>\r\n\r\n\r\n\r\n For example:<\/p>\r\n\r\n\r\n\r\n DML commands are often part of a more extensive database language, for instance, SQL (Structure Query Language). These DML commands may have a specific syntax to manage data in that language.\u00a0<\/p>\r\n\r\n\r\n\r\n DML Commands provide a way to precisely read, update, delete, or merge data. In the beginning, DML commands were part of computer programs only, but with the popularity of SQL, they have now become a part of database management.<\/p>\r\n\r\n\r\n\r\n Data Manipulation Languages (DML) have two primary classifications: Procedural and Non-procedural programming (declarative programming).<\/p>\r\n\r\n\r\n\r\n Data Control Language (DCL) provides commands to add more rights and permissions to different aspects of database parameters inside an RDBMS. Grant and Revoke are part of the DCL command in SQL.<\/p>\r\n\r\n\r\n\r\n The Grant command adds access privileges to a specific database.<\/p>\r\n\r\n\r\n\r\n Syntax:<\/p>\r\n\r\n\r\n\r\n Example:<\/p>\r\n\r\n\r\n\r\n The Revoke command provides a way to remove specific permissions from the given user.<\/p>\r\n\r\n\r\n\r\n Syntax:<\/p>\r\n\r\n\r\n\r\n Example:<\/p>\r\n\r\n\r\n\r\n Transaction Control Language or TCL represents the transactions in query handling in RDBMS. Commit, Rollback, and SAVEPOINT are the three main TCL commands.<\/p>\r\n\r\n\r\n\r\n The Commit command saves all the transactions to a specific database.<\/p>\r\n\r\n\r\n\r\n Syntax:<\/p>\r\n\r\n\r\n\r\n Example:<\/p>\r\n\r\n\r\n\r\n The rollback command allows you to return or undo any transaction that is not present in the database.\u00a0<\/p>\r\n\r\n\r\n\r\n Syntax:<\/p>\r\n\r\n\r\n\r\n Example:<\/p>\r\n\r\n\r\n\r\n Here is the syntax for SAVEPOINT to specify and set a savepoint in the transaction.<\/p>\r\n\r\n\r\n\r\n Syntax:<\/p>\r\n\r\n\r\n\r\n \u00a0Example:<\/p>\r\n\r\n\r\n\r\n DQL, also known as Data Query Language (DQL), comprises the main commands used to fetch information or data from a database.\u00a0<\/p>\r\n\r\n\r\n\r\n SELECT is the primary fundamental query command used with FROM and to give direction to the commands.<\/p>\r\n\r\n\r\n\r\n For instance:<\/p>\r\n\r\n\r\n\r\n SELECT writer_name<\/p>\r\n\r\n\r\n\r\n FROM book_writer<\/p>\r\n\r\n\r\n\r\n WHERE age > 60;<\/p>\r\n\r\n\r\n\r\n This query or command will fetch the list of writers who have written books and are aged more than 60.<\/p>\r\n Here is a short list of all DML commands and their specific functions in the SQL programming language.<\/p>\r\n \r\n\r\n<\/p>\r\n \r\n\r\n<\/p>\r\n \r\n\r\n<\/p>\r\n \r\n\r\n<\/p>\r\n \r\n\r\n<\/p>\r\n The INSERT query command in SQL provides a way to add new rows of information or data inside a specific database of the RDBMS. INSERT can be executed using two syntaxes:<\/p>\r\n \r\n\r\n<\/p>\r\n Syntax:<\/p>\r\n \r\n\r\n<\/p>\r\nTypes of Commands in SQL\u00a0<\/strong><\/h2>\r\n\r\n\r\n\r\n
\r\n
1) DDL<\/strong><\/h3>\r\n\r\n\r\n\r\n
\r\n
\r\n\r\n
\r\n Create table table_name (Datatypes, Column_name[,\u2026]);<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n \r\n\r\n
\r\n Create table mines;Create view for_learn;Create database sqltutorial;<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n\r\n\r\n \r\n
\r\n\r\n
\r\n DROP table;<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n \r\n\r\n
\r\n Drop table mines;Drop database;Drop object_type object_name;Drop view for_learn;<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n\r\n\r\n \r\n
\r\n\r\n
\r\n ALTER table table_name ADD row_name row-definition;<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n \r\n\r\n
\r\n ALTER Table Modify (Row Definition \u2026..);<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n \r\n\r\n
\r\n ALTER table mines add subject varchar;<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n\r\n\r\n \r\n
3) DCL<\/strong><\/h3>\r\n\r\n\r\n\r\n
\r\n
\r\n\r\n
\r\n GRANT SELECT, UPDATE ON TABLE_NAME to USER, SPECIFIC_USER;<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n \r\n\r\n
\r\n GRANT SELECT ON Users to Sam@admin;<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n\r\n\r\n \r\n
\r\n\r\n
\r\n REVOKE privilege_nameON object_nameFROM {user_name |PUBLIC |role_name}<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n \r\n\r\n
\r\n REVOKE SELECT, UPDATE ON student FROM BBA, MBA;<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n\r\n\r\n 4) TCL<\/strong><\/h3>\r\n\r\n\r\n\r\n
\r\n
\r\n\r\n
\r\n Commit;<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n \r\n\r\n
\r\n DELETE FROM StudentsWHERE AdmissionNo = 35;Commit;<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n\r\n\r\n \r\n
\r\n\r\n
\r\n ROLLBACK;<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n \r\n\r\n
\r\n DELETE FROM StudentsWHERE AdmissionNo = 35;ROLLBACK;<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n\r\n\r\n \r\n
\r\n\r\n
\r\n SAVEPOINT SAVEPOINT_NAME;<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n \r\n\r\n
\r\n SAVEPOINT AdmissionNo;<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n\r\n\r\n 5) DQL<\/strong><\/h3>\r\n\r\n\r\n\r\n
\r\n
List of DML Commands in SQL<\/strong><\/h2>\r\n
\r\n
The Syntax for DML Commands<\/strong><\/h2>\r\n
\r\n