Databases serve as organized digital containers for storing various kinds of information. Much like managing physical records, the data inside a database can be created, altered, or erased. Below are several essential operations that are typically performed when working with databases:
1. Creating a New Database
Establishing a fresh database is like adding a brand-new cabinet for storing categorized files. For instance, to set up a database named
RUMAHSAKIT, the SQL instruction would look like:CREATE DATABASE RUMAHSAKIT;
2. Removing an Existing Database
Deleting a database is similar to disposing of an entire file cabinet, including all the folders and contents it holds. If you have a database called
RUMAHSAKIT containing several tables like PASIEN, DOKTER, and TRANSAKSI, you can remove the whole structure with:DROP DATABASE RUMAHSAKIT;
3. Adding a Table to a Database
Creating a table is comparable to placing a new folder into a filing system. For example, if the
RUMAHSAKIT database needs a table named PASIEN, the SQL syntax would be:CREATE TABLE PASIEN (PasienID INT,LastName VARCHAR(255),FirstName VARCHAR(255),Address VARCHAR(255),City VARCHAR(255));
4. Deleting a Table from a Database
Removing a table is like getting rid of an outdated folder and everything inside it. To delete the
PASIEN table from your hospital database, the following command is used:DROP TABLE PASIEN;
5. Inserting New Records into a Table
To add fresh data entries into a table, you can use an
INSERT command. Say you want to enter a new patient with ID 1, last name Suryadi, first name Andri, address Jalan Pondok Cabe, and city Tangerang Selatan, the SQL would be:INSERT INTO PASIEN (PasienID, LastName, FirstName, Address, City)VALUES (1, 'Suryadi', 'Andri', 'Jalan Pondok Cabe', 'Tangerang Selatan');
6. Displaying Data from a Table
Fetching data is akin to pulling out a sheet of information from a folder. To view all existing entries in the
PASIEN table, the query would be:SELECT * FROM PASIEN;
7. Modifying Existing Entries
If you need to correct or change a record, such as updating a patient’s address, you would use the
UPDATE statement. For example, changing the address of the patient with ID 1 might look like this:UPDATE PASIENSET Address = 'Jl Pondok Cabe'WHERE PasienID = 1;
8. Removing Specific Records
Erasing a single row of data, like deleting a patient entry, is done through a
DELETE command. To remove the record of patient with ID 1, the query is:DELETE FROM PASIENWHERE PasienID = 1;
Final Notes
Commands that involve creating the structure of a database—like setting up databases and tables—are typically performed once. In contrast, operations involving data manipulation such as insertions, updates, and deletions, are continuous and form the core of day-to-day database management activities.
Reference:
Ruliah, Suryadi Andri. Basis Data, 2024
.png)
No comments:
Post a Comment