Before getting to know more about DDL (Data Definition Language) and DML (Data Manipulation Language), it is necessary to know beforehand, that this discussion is included in database technology, which includes data management methods or techniques, both image text data and other data. Database management is done by writing command codes in the form of SQL Queries that you must enter according to your needs. The following below is the complete understanding of DDL and DML.
For the understanding of DDL and DML itself, that is if DDL (Data Definition Language) is a collection of SQL commands that you can use to manage, change the structure of datatype objects in databases such as indexes, tables, triggers, views and so on.
While DML (Data Manipulation Language) itself is a collection of commands that function for database management such as creating tables, creating new databases.
Examples of DDL and DML Commands
As mentioned earlier, DDL (Data Definition Language) and DML (Data Manipulation Language) are sets of commands that are used to perform functions to create, modify, or delete existing database entities. Therefore, below is a set of commands you can try to manage the database:
Relasi Basis Data
1. DDL (Bahasa Definisi Data)
DDL can be used to operate the structural schema on the database, the main commands that can be used in DDL (Data Definition Language) are CREATE, RENAME, ALTER, DROP. Create is the command used to create new databases and tables. While Rename is a command used to change names such as table names, and DROP is a command used to delete an object.
Contoh 1:
CREATE
TABLE Buku_Perpus( id INTEGER PRIMARY KEY, kode_buku VARCHAR(20) NULL,
judul_buku VARCHAR(225) NOT NULL, tanggal_terbit DATE NULL );
In the command example above, it means that a new table named Buku_Library will be created which has an entity column such as id which is given a primary key or cannot be the same as other data, there will also be a Kode_Book column with the data type varchar which has a capacity of holding up to 20 characters and can be left blank by entering a NULL code. Apart from that, there is also a book_title with data type Varchar with a capacity of 225 characters and cannot be empty with NOT NULL code. Lastly, there is a publish_date with data type DATE and can be left blank with a NULL code.
Contoh 2:
Alter TABLE Buku ADD Penulis Varchar(100);
Alter TABLE Buku Drop Column Judul_buku;
In the example above there are two command lines, each of which has a different function, in the first line there is the ALTER command which functions to change, in the first line it functions to change the table structure, where a new column will be created later. added with the name Author with data type VARCHAR with a capacity of 100 characters and will be added to the Books table.
Meanwhile, the second line is a command that is also used to change the table structure, but it is different from the first line which adds a column, the second line actually parses the column, which will be removed is the Book-Title column contained in a table called the Book table, the Hal command The main command used is the ALTER command, but the only difference is the use of ADD and DROP.
Contoh 3:
DROP TABLE Buku;
In the one-line SQL command example above, there is a command that functions to delete, where the main DROP command is used, which means delete, after the DROP command, it is followed by the TABLE command, which means that the object to be deleted is TABLE , followed by the name of the object clearly, namely books, so that the command reads Delete the Book Table.
2. DML (Bahasa Manipulasi Data)
DML is a set of commands used to manage databases such as creating new, adding, deleting and displaying, the main commands are UPDATE, DELETE, INSERT, SELECT. The UPDATE command is used when you want to update data, and the delete command is used when you want to delete data. Apart from that there is also the INSERT command which you can use to enter data into the database, and finally there is the SELECT command which is used to display data. that you have entered.
Contoh :
SELECT * FROM Buku;
UPDATE Buku SET Judul_buku = “Programmer” WHERE id = 1123;
INSERT INTO Buku (id,kode_buku,judul_buku,tanggal_terbit) values(1124, “KoD2?, “Desainer”, “2013-01-11?);
In the example of the DML (Data Manipulation Language) command above, there are three commands that have different functions, in the first line is a command that functions to display data, there is the main command, namely SELECT which means display, then followed by the asterisk code, which means 'all' . Followed by the FROM Book code, which means Table Book, if it is read in full it will be read. Displays all data contained in the book table.
Then in the second line there is a command that uses the main code UPDATE Book which means it will change existing data in the book table, followed by SET Book_title = 'Programmer' which means existing data will be changed with the word 'Programmer'. then what to change? contained in the last code WHERE id='123?, the book title that will be changed to 'programmer' is the book title that has id 123.
Finally, there is a line of code that functions to add data, there is the INSERT INOT Buku function, which means that data will be inserted into the Book table followed by column names sequentially. Then followed by Values with the contents of the data in the order of the column names, finally closed with double quotes in each SQL command.
29