Queries with SQL - An SQL reference guide for brother

SQL is a standard language for accessing and manipulating databases.

Some Definitions: SQL is a domain-specific language used in programming and designed for managing data held in a relational database management system, or for stream processing in a relational data stream management system. It is particularly useful in handling structured data

The first thing to understand about SQL is that SQL isn’t a procedural language, as are Python, C, C++, C#, and Java. To solve a problem in a procedural language, you write a procedure — a sequence of commands that performs one specific operation after another until the task is complete. The procedure may be a straightforward linear sequence or may loop back on itself, but in either case, the programmer specifies the order of execution.

List of all SQL Keywords

1. ADD

ADD Adds a column in an existing table

2. ADD CONSTRAINT

ADD CONSTRAINT Adds a constraint after a table is already created

3. ALTER

ALTER Adds, deletes, or modifies columns in a table, or changes the data type of a column in a table

4. ALTER COLUMN

ALTER COLUMN Changes the data type of a column in a table

5. ALTER TABLE

ALTER TABLE Adds, deletes or modifies columns in a table

6. ALL

ALL Returns true if all of the subquery values meet the condition

7. AND

AND Only includes rows where both conditions are true

8. ANY

ANY Returns true if any of the subquery values meet the condition

9. AS

AS Renames a column or table with an alias

10. ASC

ASC Sorts the result set in ascending order

11. BACKUP DATABASE

BACKUP DATABASE Creates a back up of an existing database

12. BETWEEN

BETWEEN Selects values within a given range

13. CASE

CASE Creates different outputs based on conditions

14. CHECK

CHECK A constraint that limits the value that can be placed in a column

15. COLUMN

COLUMN Changes the data type of a column or deletes a column in a table

16. CONSTRAINT

CONSTRAINT Adds or deletes a constraint

17. CREATE

CREATE creates a database, index, view, table, or procedure

18. CREATE DATABASE

CREATE DATABASE creates a new SQL database

19. CREATE INDEX

CREATE INDEX creates an index on a table (allows duplicate values)

20. CREATE OR REPLACE VIEW

CREATE OR REPLACE VIEW updates a view

21. CREATE TABLE

CREATE TABLE creates a new table in the database

22. CREATE PROCEDURE

CREATE PROCEDURE creates a stored procedure

23. CREATE UNIQUE INDEX

CREATE UNIQUE INDEX creates a unique index on a table (no duplicate values)

24. CREATE VIEW

CREATE VIEW creates a view based on the result set of a SELECT statement

25. DATABASE

DATABASE creates or deletes an SQL database

26. DEFAULT

DEFAULT a constraint that provides a default value for a column

27. DELETE

DELETE Deletes rows from a table

28. DESC

DESC Sorts the result set in descending order

29. DISTINCT

DISTINCT Selects only distinct (different) values

30. DROP

DROP Deletes a column, constraint, database, index, table, or view

31. DROP COLUMN

DROP COLUMN Deletes a column in a table

32. DROP CONSTRAINT

DROP CONSTRAINT Deletes a UNIQUE, PRIMARY KEY, FOREIGN KEY, or CHECK constraint

33. DROP DATABASE

DROP DATABASE Deletes an existing SQL database

34. DROP DEFAULT

DROP DEFAULT Deletes a DEFAULT constraint

35. DROP INDEX

DROP INDEX Deletes an index in a table

36. DROP TABLE

DROP TABLE Deletes an existing table in the database

37. DROP VIEW

DROP VIEW Deletes a view

38. EXEC

EXEC Executes a stored procedure

39. EXISTS

EXISTS Tests for the existence of any record in a subquery

40. FOREIGN KEY

FOREIGN KEY is a constraint that is a key used to link two tables together

41. FROM

FROM Specifies which table to select or delete data from

42. FULL OUTER JOIN

FULL OUTER JOIN returns all rows when there is a match in either left table or right table

43. GROUP BY

GROUP BY Groups the result set (used with aggregate functions: COUNT, MAX, MIN, SUM, AVG)

44. HAVING

HAVING Used instead of WHERE with aggregate functions

45. IN

IN Allows you to specify multiple values in a WHERE clause

46. INDEX

INDEX Creates or deletes an index in a table

47. INNER JOIN

INNER JOIN Returns rows that have matching values in both tables

48. INSERT INTO

INSERT INTO Inserts new rows in a table

49. INSERT INTO SELECT

INSERT INTO SELECT Copies data from one table into another table

50. IS NULL

IS NULL Tests for empty values

51. IS NOT NULL

IS NOT NULL Tests for non-empty values

52. JOIN

JOIN Joins tables

53. LEFT JOIN

LEFT JOIN Returns all rows from the left table and the matching rows from the right table

54. LIKE

LIKE Searches for a specified pattern in a column

55. LIMIT

LIMIT specifies the number of records to return in the result set

56. NOT

NOT Only includes rows where a condition is not true

57. NOT NULL

NOT NULL is a constraint that enforces a column to not accept NULL values

58. OR

OR Includes rows where either condition is true

59. ORDER BY

ORDER BY Sorts the result set in ascending or descending order

60. OUTER JOIN

OUTER JOIN Returns all rows when there is a match in either left table or right table

61. PRIMARY KEY

PRIMARY KEY is a constraint that uniquely identifies each record in a database table

62. PROCEDURE

PROCEDURE A stored procedure

63. RIGHT JOIN

RIGHT JOIN Returns all rows from the right table and the matching rows from the left table

64. ROWNUM

ROWNUM Specifies the number of records to return in the result set

65. SELECT

SELECT DISTINCT Selects data from a database

66. SELECT DISTINCT

SELECT DISTINCT Selects only distinct (different) values

67. SELECT INTO

SELECT INTO Copies data from one table into a new table

68. SELECT TOP

SELECT TOP Specifies the number of records to return in the result set

69. SET

SET Specifies which columns and values should be updated in a table

70. TABLE

TABLECreates a table, or adds, deletes, or modifies columns in a table, or deletes a table or data inside a table

71. TOP

TOP Specifies the number of records to return in the result set

72. TRUNCATE TABLE

TRUNCATE TABLE Deletes the data inside a table, but not the table itself

73. UNION

UNION Combines the result set of two or more SELECT statements (only distinct values)

74. UNION ALL

UNION ALL Combines the result set of two or more SELECT statements (allows duplicate values)

75. UNIQUE

UNIQUE A constraint that ensures that all values in a column are unique

76. UPDATE

UPDATE Updates existing rows in a table

77. VALUES

VALUES Specifies the values of an INSERT INTO statement

78. VIEW

VIEW Creates, updates, or deletes a view

79. WHERE

WHERE Filters a result set to include only records that fulfill a specified condition