SQL
SQL Commands overview

Custom SQL Language User Manual

Introduction

This custom SQL language is a variant of SQL designed to interact with relational databases, with additional features tailored for specific operations. This manual describes the various commands, operators, and syntax for working with the custom SQL language.


1. SQL Commands

1.1 SELECT Command

The SELECT statement is used to retrieve data from one or more tables. This language supports various options to filter, sort, and group the retrieved data.

Syntax:

SELECT column1, column2, ...
FROM table_name
WHERE condition
GROUP BY column1
HAVING condition
ORDER BY column1;
  • FROM: Specifies the table or tables from which to retrieve data.
  • WHERE: Filters rows based on specified conditions.
  • GROUP BY: Groups the result set based on one or more columns.
  • HAVING: Filters groups based on aggregate functions.
  • ORDER BY: Sorts the result set.

Example:

SELECT name, age
FROM users
WHERE age > 18
ORDER BY age DESC;

This query retrieves the names and ages of users older than 18, sorted by age in descending order.


1.2 INSERT Command

The INSERT statement is used to add new records to a table.

Syntax:

INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);

Example:

INSERT INTO employees (first_name, last_name, department)
VALUES ('John', 'Doe', 'Marketing');

This query inserts a new record for an employee named John Doe into the Marketing department.


1.3 UPDATE Command

The UPDATE command modifies existing data in a table.

Syntax:

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

Example:

UPDATE employees
SET department = 'HR'
WHERE last_name = 'Doe';

This query changes the department of all employees with the last name 'Doe' to HR.


1.4 DELETE Command

The DELETE command removes data from a table.

Syntax:

DELETE FROM table_name
WHERE condition;

Example:

DELETE FROM employees
WHERE department = 'HR';

This query deletes all employees in the HR department.


2. Operators and Expressions

The custom SQL language supports several types of operators for use in expressions.

2.1 Comparison Operators

  • =: Equal to
  • <> or !=: Not equal to
  • <, <=, >, >=: Less than, less than or equal to, greater than, greater than or equal to

Example:

SELECT name
FROM products
WHERE price >= 100;

This query selects products with a price greater than or equal to 100.


2.2 Logical Operators

  • AND: Combines multiple conditions, both must be true.
  • OR: Combines conditions, at least one must be true.
  • NOT: Negates a condition.

Example:

SELECT name
FROM users
WHERE age > 18 AND city = 'New York';

This query selects users who are older than 18 and live in New York.


3. Custom Features

This language includes unique tokens and commands that extend the standard SQL functionality.

3.1 LEDGER and CONTRACT Tokens

  • LEDGER: Used in queries related to transactional records or ledger-based databases.
  • CONTRACT: Might be used for querying smart contracts or blockchain data.

Example:

SELECT transaction_id, amount
FROM ledger
WHERE contract_id = 'ABC123';

This query retrieves all transactions associated with a specific contract.

3.2 CRYPTONET Token

The CRYPTONET token likely deals with encrypted data or networks involved in data storage or transfer. More details would be needed to explain the full usage of this token.


4. Data Types

The custom SQL language supports various data types for use in table definitions:

  • INT: Integer values.
  • FLOAT: Floating-point numbers.
  • VARCHAR(n): Variable-length string.
  • BOOLEAN: True or false values.
  • DATE: Date values.
  • JSON: JSON formatted data (custom token JSON suggests support for JSON data).

5. SQL Functions

5.1 Aggregate Functions

Aggregate functions perform calculations on multiple rows.

  • COUNT(): Returns the number of rows.
  • SUM(): Returns the sum of a numeric column.
  • AVG(): Returns the average of a numeric column.
  • MIN(): Returns the minimum value.
  • MAX(): Returns the maximum value.

Example:

SELECT COUNT(*), AVG(salary)
FROM employees
WHERE department = 'Sales';

This query returns the number of employees and the average salary in the Sales department.


5.2 String Functions

  • UPPER(): Converts a string to uppercase.
  • LOWER(): Converts a string to lowercase.
  • CONCAT(): Concatenates two strings.

Example:

SELECT UPPER(first_name)
FROM employees;

This query converts all first names of employees to uppercase.


6. Joins

6.1 INNER JOIN

The INNER JOIN returns records that have matching values in both tables.

Syntax:

SELECT column1, column2, ...
FROM table1
INNER JOIN table2
ON table1.common_column = table2.common_column;

Example:

SELECT employees.first_name, departments.department_name
FROM employees
INNER JOIN departments
ON employees.department_id = departments.department_id;

Conclusion

This custom SQL language builds upon standard SQL functionality with additional tokens and features like LEDGER, CRYPTONET, and CONTRACT. Users can construct complex queries with familiar SQL structures as well as specialized commands for working with contracts, ledgers, and potentially encrypted data.


Let me know if you would like to include any more details or focus on a specific feature in this custom SQL language.