SQL - Syntax pt.1 Flashcards

1
Q

SQL statements

In SQL * means

A

All record

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

SQL statements

used to select data from a database.

A

SQL SELECT Statement

SELECT CustomerName, City FROM Customers;

Syntax:

SELECT column1, column2, …
FROM table_name;

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

SQL statements

is used to return only different values.

A

SQL DISTINCT Clause

SELECT DISTINCT Country FROM Customers;

Syntax:

SELECT DISTINCT column1, column2, …
FROM table_name;

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

SQL statements

used to filter records.

It is used to extract only those records that fulfill a specified condition

A

SQL WHERE Clause

SELECT * FROM Customers
WHERE Country=’Mexico’;

Syntax:

SELECT column1, column2, …
FROM table_name
WHERE condition;

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

SQL statements

this operator is used when all the conditions are true.

A

AND operator

SELECT * FROM Customers
WHERE Country = ‘Germany’ AND Name = ‘Tom’;

Syntax:

SELECT column1, column2, …
FROM table_name
WHERE condition1 AND condition2 AND condition3 …;

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

SQL statements

operator is used if any one of the conditions are true.

A

OR operator

SELECT *
FROM Customers
WHERE Country = ‘Germany’ OR Country = ‘Spain’

Syntax:

SELECT column1, column2, …
FROM table_name
WHERE condition1 OR condition2 OR condition3 …;

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

SQL statements

allows you to specify multiple values in a WHERE clause.

A

SQL IN Clause

SELECT * FROM Customers
WHERE Country IN (‘Germany’, ‘France’, ‘UK’);

Syntax:

SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, …);

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

SQL statements

selects values within a given range. The values can be numbers, text, or dates.

A

SQL BETWEEN Clause

SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;

Syntax:

SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

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

SQL statements

is used in a WHERE clause to search for a specified pattern in a column

A

SQL LIKE Clause

SELECT * FROM Customers
WHERE CustomerName LIKE ‘a%’;

Syntax:

SELECT column1, column2, …
FROM table_name
WHERE columnN LIKE pattern;

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

SQL statements

is used to sort the result-set in ascending or descending order.

A

SQL ORDER BY Clause

SELECT * FROM Products
ORDER BY Price;

Syntax:

SELECT column1, column2, …
FROM table_name
ORDER BY column1, column2, … ASC|DESC;

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

SQL statements

thhis statement groups rows that have the same values into summary rows

A

SQL GROUP BY Clause

SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country;

Syntax:

SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);

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

SQL statements

this function returns the number of rows that matches a specified criterion

A

SQL COUNT Clause

SELECT COUNT(*)
FROM Products;

Syntax:

SELECT COUNT(column_name)
FROM table_name
WHERE condition;

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

SQL statements

this clause was added to SQL because the WHERE keyword cannot be used with aggregate functions.

A

SQL HAVING Clause

SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5;

Syntax:

SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);

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

SQL statements

this statement is used to create a new table in a database.

A

SQL CREATE TABLE Statement

CREATE TABLE Persons (
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);

Syntax:

CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
….
);

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

SQL statements

this statement is used to drop an existing table in a database.

A

SQL DROP TABLE Statement

DROP TABLE Shippers;

Syntax:

DROP TABLE table_name;

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

SQL statements

statement is used to create indexes in tables.

Indexes are used to retrieve data from the database more quickly than otherwise.

A

SQL CREATE INDEX Statement

CREATE INDEX idx_lastname
ON Persons (LastName);

Syntax:

CREATE INDEX index_name
ON table_name (column1, column2, …);

17
Q

SQL statements

this statement is used to delete an index in a table.

A

SQL DROP INDEX Statement

Syntax:

ALTER TABLE table_name
DROP INDEX index_name;

18
Q

SQL statements

this command deletes the data inside a table, but not the table itself.

A

SQL TRUNCATE TABLE Statement

TRUNCATE TABLE Shippers;

Syntax:

TRUNCATE TABLE table_name;

19
Q

SQL statements

this statement is used to add, delete, or modify columns in an existing table.

A

SQL ALTER TABLE Statement

ALTER TABLE table_name
ADD column_name datatype;

ALTER TABLE table_name
ADD,DROP,MODIFY,RENAME column_name datatype;

20
Q

SQL statements

this statement is used to insert new records in a table.

A

SQL INSERT INTO Statement

INSERT INTO Customers (CustomerName)
VALUES (‘Tom’);

Syntax:

INSERT INTO table_name (column1, column2, column3, …)
VALUES (value1, value2, value3, …);

21
Q

SQL statements

this statement is used to modify the existing records in a table.

A

SQL UPDATE Statement

UPDATE Customers
SET ContactName=’Juan’
WHERE Country=’Mexico’;

Syntax:

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

22
Q

SQL statements

this statement is used to delete existing records in a table

A

SQL DELETE Statement

DELETE FROM Customers WHERE CustomerName=’Alfreds Futterkiste’;

Syntax:

DELETE FROM table_name WHERE condition;

23
Q

SQL statements

this statement is used to create a new SQL database.

A

SQL CREATE DATABASE Statement

CREATE DATABASE testDB;

Syntax:

CREATE DATABASE databasename;

24
Q

SQL statements

this statement is used to drop an existing SQL database.

A

SQL DROP DATABASE Statement

DROP DATABASE testDB;

Syntax:

DROP DATABASE databasename;

25
Q

SQL statements

s used to select a database and perform SQL operations into that database.

A

SQL USE Statement

USE MyDatabase ;

Syntax:

USE database_name;

26
Q

SQL statements

a command that is used for storing changes performed by a transaction

A

SQL COMMIT Statement

DELETE from Customer where State = ‘Texas’;
COMMIT;

Syntax:

COMMIT;

27
Q

SQL statements

a command that is used for reverting changes performed by a transaction.

A

SQL ROLLBACK Statement

DELETE from Customer where State = ‘Texas’;
ROLLBACK;

Syntax:

ROLLBACK

28
Q

identification

SQL is followed by a unique set of rules and guidelines called

A

Syntax.

29
Q

identification

all the statements end with a

A

semicolon
(;)

30
Q

identification

All the SQL statements start with any of the keywords like

A

SELECT, INSERT, UPDATE,
DELETE, ALTER, DROP, CREATE, USE, SHOW

31
Q

identification

The most important point to be noted here is that SQL is____which means SELECT and select have same meaning

A

case insensitive