Introduction to SQL 157a (5) Flashcards

1
Q

What is SQL?
What does it stand for?

A

○ SQL stands for Structured Query Language. It is used for storing and managing data in
relational database management system (RDMS).
○ It is a standard language for Relational Database System. It enables a user to create, read, update and delete relational databases and tables.
○ All the RDBMS like MySQL, Informix, Oracle, MS Access and SQL Server use SQL as their
standard database language.
○ SQL allows users to query the database in a number of ways, using English-like statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why is SQL used?

A

SQL is widely popular because it offers the following advantages −
1. Allows users to access data in the relational database management systems.
2. Allows users to describe the data.
3. Allows users to define the data in a database and manipulate that data.
4. Allows to embed within other languages using SQL modules, libraries & pre-compilers.
5. Allows users to create and drop databases and tables.
6. Allows users to create view, stored procedure, functions in a database.
7. Allows users to set permissions on tables, procedures and views.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does SQL work?

A

How SQL Works?
○ When an SQL command is executing for any RDBMS, then the system figure out the best way to carry out the request and the SQL engine determines that how to interpret the task.
○ In the process, various components are included. These components can be optimization Engine, Query engine, Query dispatcher, classic, etc.
○ All the non-SQL queries are handled by the classic query engine, but SQL query engine won’t handle logical files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Important SQL characteristics

A

● SQL is easy to learn.
● SQL is used to access data from relational database management systems.
● SQL can execute queries against the database.
● SQL is used to describe the data.
● SQL is used to define the data in the database and manipulate it when needed.
● SQL is used to create and drop the database and table.
● SQL is used to create a view, stored procedure, function in a database.
● SQL allows users to set permissions on tables, procedures, and views

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

SQL advantages

A
  • High Speed
  • No coding needed
  • Well defined standards
  • portability
  • interactive language
  • Multiple data view
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

SQL Data types

A
  • SQL datatype is used to define the values that a column can contain
  • Every column is required to have a name and data type in the database table
  1. Binary DataType
  2. Numeric Datatype
  3. Extract Numberic Datatype
  4. String Datatype
  5. Date Datatype
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are Binary Datatypes?

A

There are Three types of
binary Datatypes which are
given below:

  • Binary: It has a maximum length of 8000 bytes. It contains fixed length binary data
  • Varbinary: It has a maximum length of 8000 bytes. It contains variable length binary data
  • image: it has a maximum lenght of 2,147,483,647 bytes. It contains variable length binary data.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Approximate Numeric Datatype

A

The subtypes are below:

  • float: It is used to specify a floating point value
  • real: it specifies a single precision floating point number
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Exact Numeric Datatype

A

Subtypes are given below:

  • int: it is used to specify an integer value
  • smallint: it is used to specify fmall integer value.
  • bit: it has the number of bits to store
  • decimal: it specifies a numeric value that can have a decimal number
  • numeric: it is used to specify a numeric value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Character String Datatype

A

subtypes given below

  • It has a maximum length of 8000 characters. It contains Fixed length non unicode characters.
  • varchar: it has a maximum length of 8000 characters. It contains variable-length non unicode characters
  • text: it has a maximum length of 2,147,483,647 characters. it contains variable length non unicode characters.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Date and time datatypes

A

subtypes given below

  • date: it is used to store the year, month , and days value.
  • time: it is used to store the hour, minute , and second values
  • timestamp: it stores the year, month, day, hour, minute, and the second value.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

SQL Commands

A

○ SQL commands are instructions. It is used to communicate with the database. It is also
used to perform specific tasks, functions, and queries of data.
○ SQL can perform various tasks like create a table, add data to tables, drop the table,
modify the table, set permission for users.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Types of SQL Commands

A

DDL, DML, DCL, TCL, DQL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

DDL Commands

A
  • Create
  • Drop
  • Alter
  • Truncate
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

DML Commands

A
  • Insert
  • update
  • delete
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

DCL Commands

A
  • Grant
  • Revoke
17
Q

TCL Command

A
  • Commit
  • Rollback
  • Save point
18
Q

DQL Commands

A
  • Select
19
Q

SQL Syntax

A

SQL syntax is a unique set of rules and guidelines to be followed while writing SQL statements.
All the SQL statements start with any of the keywords like SELECT, INSERT, UPDATE, DELETE,
ALTER, DROP, CREATE, USE, SHOW and all the statements end with a semicolon (;).
SQL is case insensitive

20
Q

SQL Operators

A

● An SQL operator is a reserved word or a character used primarily in an SQL statement WHERE clause to perform operation(s), such as comparisons and arithmetic operations.
● These Operators are used to specify conditions in an SQL statement and to serve as conjunctions for multiple conditions in a statement.
● Types of Operator in SQL
1. Arithmetic operators
2. Comparison operators
3. Logical operators
4. Operators used to negate conditions

21
Q

SQL Arithmetic Operators

A

SQL Arithmetic Operators are used to perform mathematical operations on the numerical values. List of all the arithmetic operators available in SQL

Operator: +, -, *, / , %

22
Q

SQL Comparison Operators

A

● SQL Comparison Operators test whether two given Expressions are the same or not.
● These operators are used in SQL conditional
statements while comparing one expression
with another and they return a Boolean value which can be either TRUE or
FALSE.

23
Q

SQL Logical Operators

A

ALL TRUE if all of a set of comparisons are TRUE.
AND TRUE if all the conditions separated by AND are TRUE.
ANY TRUE if any one of a set of comparisons are TRUE.
BETWEEN TRUE if the operand lies within the range of comparisons.
EXISTS TRUE if the subquery returns one or more records
IN TRUE if the operand is equal to one of a list of expressions.
LIKE TRUE if the operand matches a pattern specially with wildcard.
NOT Reverses the value of any other Boolean operator.
OR TRUE if any of the conditions separated by OR is TRUE
IS NULL TRUE if the expression value is NULL.
SOME TRUE if some of a set of comparisons are TRUE.
UNIQUE The UNIQUE operator searches every row of a specified table for uniqueness
(no duplicates).

24
Q

SQL Operator Precedence

A

The operator precedence in SQL is the sequence in which the SQL evaluates the different operators in a given
expression. The operators with higher precedence get evaluated first.

Lists all SQL operators as per their precedence. The operators with the highest precedence are at the top and the
operators with the lowest precedence are at the bottom.