Structured Query Language or SQL is the most well-known language in the world and also the most popular. It is used to execute commands in Relational Databases, that is, based on tables. It is through it that we create databases, tables, columns, indices, grant and revoke privileges to users and query the data stored in the database. SQL is a declarative language divided into sets of commands Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), Transactional Control Language (TCL) and Data Query Language (DQL). Let's describe the SQL language command sets using PostgreSQL as an example
Data Definition Language She is responsible for creating and altering commands in the database.
The main DDL commands are:
used to create the structure of data and tables.
1CREATE TABLE nome_tabela ( 2 id SERIAL NOT NULL, 3 coluna_01 varchar(40), 4 coluna_02 numeric (16,2), 5 coluna_03 date 6 );
used to add, delete or modify columns of an existing table.
ALTER TABLE name_table ADD column_04 varchar(50);
DROP:- Command used to delete table structure.
DROP TABLE name_table;
INSERT :- INSERT INTO name_table
UPDATE:- update name_table SET column_04 = 'novo_value_column_04' WHERE id = 20;
DELETE :- delete from name_table WHERE id = 20;
GRANT :- CREATE USER name_user WITH PASSWORD 'senha_user';
REVOKE :- REVOKE ALL ON name_table FROM name_user;
COMMIT :- INSERT INTO name_table
ROLLBACK :- DELETE FROM name_table WHERE id = 20;
NoSQL ( or non-relational) databases use a different storage standard than SQL. The great advantage of this technology is the ability to scale business operations in a simpler and more economical way than in relational databases. NoSQL also provides better performance for managing data in organizations, as there is no need to group the data in a schema of tables to use the information. In MongoDB, sets of documents are called “Collections”. They would be the analogues of tables in Postgres, with the fundamental difference that your documents do not need to respect a rigid table schema, as in relational databases . As in the case of relational databases, these collections are saved within “databases” in the same database .
As mentioned at the beginning “…one of our biggest decisions should be between a relational (SQL) and non-relational (NoSQL) data structure” , to answer the question Which database is the right one to store information from a system? We should look at the business rule of the system. Relational Databases (SQL) are a good choice for any business that will benefit from their pre-defined structure and schema. For example, applications that require multi-line transactions or that run on legacy systems will thrive with the Relational Data (SQL) framework . Non-Relational Databases (NoSQL) on the other hand, are a good choice for fast growing businesses or databases without clear schema definitions. In case you can't define a schema for your database, realize that you are always denormalizing data schemas. If your schema is constantly changing, the Non-Relational Data (NoSQL) framework may be the right choice for you. Interested and want to know and learn more about Databases? Check out our Database course and come master this language with us!
Dont miss out on the news!
Join the MAKE NOW academy to receive exclusive content every week!