SQL Queries
2022, Apr 04
Sql Language Theory
SQL Notes.
- Origins IBM’s research labs.
- Early 1970’s.
- SQL (Structure Query Language).
Database (DB)
- Database.- A collection of integrated records (any collection of related information).
- Record.- A representation of a conceptual object.
- Database consists of data and metadata.
- DB’s can be stored in different ways.
Database Management Systems (DBMS)
- SQL is just a language, and there for special software needs to be used in order to perform queries.
- A query is a question you ask the database.
- DBMS.- Is a special software or program that helps users create and maintain a database.
- It makes it easy to manage large amounts of information.
- Handles security, backups, import/export of data.
DBMS Diagram
Reference for the image. 1
Types of Databases
- Relational Databases (SQL) - Organize data intone or more tables. - Each table has columns and rows. - A unique key identifies each row.
- Non-Relational Databases (No SQL, not just SQL) -Organize data is anything but traditional table. - key: value stores. - Documents (JSON, XML, BLOB, etc.) - Flexible tables. - graphs, key-value hash, keys mapped into values.
Software
Relational Databases Management Systems (RDMMS)
- Helps users create and maintain a relational database.
- MySQL, Oracle, Postgre SQL, Maria DB, etc.
- Uses the structured query language.
- Used to perform CRUD (create, read, update, delete).
- Used to define tables and structures.
- SQL code is not always portable between applications without modification.
Non-Relational Databases Management Systems (NRDMMS)
- Helps users create and maintain a non-relational database.
- MongoDB, DynamoDB, apache Cassandra, firebase, etc.
- Implementation is specific.
- Any non-relational database falls under this category, so there is no set standard language.
- Most NRDMMS will implement their own language in order to perform CRUD, on the database.
Database Queries
- Queries are requests made to the database management system for specific information.
- As the database’s structure becomes more and more complex, it becomes more difficult to retrieve specific pieces of information.
- Queries are instructions given to the RDBMS in SQL.
Keys
- Relational databases always have a primary key, which can be the column id. Other keys are surrogate, natural, and foreign keys.
- Natural keys are used with the same purpose like in the real world.
- Foreign keys are links to other databases or tables and mark a relationship between databases and tables.
SQL
- SQL is a language used for interacting with relational databases management systems.
- You can use SQL to get the RDBMS to do things fir you. Like CRUD.
- Create, manage, design, administrate tasks, implements. etc.
- SQL implementations vary between systems.
- Concepts are the same, but implementation may vary.
SQL Types
- SQL can be referred as a hybrid language with 4 basic types of language
- Data Query Language (DQL) used to query the database for data.
- Data Definition Language (DDL) used for defining database schemas.
- Data Control Language (DCL) used for controlling access to the data in the database.
- Data Manipulation Language (DML) used for inserting, updating, and deleting data from the database.
SQL data types
- Int integer number.
- Decimal (M,N) float point number.
- Varchar string.
- BLOB binary language object.
- Date yyyy-mm-day
- Timestamp yyyy-mm-day and hsec
Table creation
Insert data into database by inserting the values in order of appeareance. You can not insert duplicate keys, beacuse a record all rady exists.
We can specify the picies of information eg. only student_id & name.
Now we drop the table.
The full code is:
-
Reference: https://www.bmc.com/blogs/dbms-database-management-systems/ ↩