SQL Commands Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is SQL?

A

It is a declarative language used for creating, querying and updating tables in a relational database.

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

What is the SELECT keyword used for?

A

Used to extract a collection of fields from a given table.

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

Show the syntax of the SELECT command:

A

SELECT ,
FROM ,
WHERE
ORDER BY

The default for ORDER BY is ascending.

Example:

SELECT CDTitle, RecordCompany
FROM CD
WHERE DatePublished = 01/01/2015
ORDER BY CDTitle

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

What are the most common ‘standard conditions’ that can be used with SQL?

A

=, <=, >=, !=, AND, OR etc.

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

What does the IN condition mean?

A

Equal to a value within a set of values.

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

What does the LIKE condition mean?

A

Similar to.

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

What does the BETWEEN…AND condition mean?

A

Within a range, including the two defining values.

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

What does the IS NULL condition mean?

A

Field doesn’t contain a value. eg CD IS NULL

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

What does NOT do?

A

Invert truth.

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

What is the ORDER BY keyword used for?

A

Gives control over how the results are displayed.

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

How would you further sort data using the ORDER BY keyword?

A

Give the command another parameter to sort by. eg SORT BY Name, Date.

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

How would you use the SELECT command to extract and combine data from multiple tables?

A

Use the SELECT command as usual but prefix the field name with the table name: tablename.fieldname

eg SELECT Song.SongTitle, Artist.ArtistName

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

What does the JOIN command do?

A

JOIN combines rows from tables based on common fields between them.

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

What is the CREATE TABLE keyword used for?

A

Used to create a new SQL table.

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

Show the syntax of the CREATE TABLE command:

A

CREATE TABLE
(

)

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

Define the CHAR(n) Data Type.

A

Character string with fixed length, n.

17
Q

Define the VARCHAR(n) Data Type.

A

Variable length character string, max length n.

18
Q

Define the BOOLEAN Data Type.

A

TRUE or FALSE.

19
Q

INTEGER, INT

A

Integer

20
Q

FLOAT(a,b)

A

Float with max digits, a, and max digits after decimal, b.

21
Q

DATE

A

Stored Day, Month, Year values.

22
Q

CURRENCEY

A

Formats numbers based on a currency.

23
Q

What is the ALTER TABLE keyword used for?

A

Used to add, delete or modify fields in an existing table.

24
Q

Show how to ADD a field using the ALTER TABLE command:

A

ALTER TABLE

ADD

25
Q

Show how to DELETE a field using the ALTER TABLE command:

A

ALTER TABLE

DROP COLUMN

26
Q

Show how to Change a data type of a field using the ALTER TABLE command:

A

ALTER TABLE

MODIFY COLUMN

27
Q

What is the INSERT keyword used for?

A

Inserting a new record.

28
Q

Show the syntax of the INSERT command:

A
INSERT INTO  (column #1, n)
VALUES (value 1, n)

Where column is the field for the data to be inserted and value is the new value.

29
Q

What is the UPDATE keyword used for?

A

Updates a record in a database.

30
Q

Show the syntax of the UPDATE command:

A

UPDATE
SET = , =
WHERE columnX = value

31
Q

What is the DELETE keyword used for?

A

Deleting a record.

32
Q

Show the syntax of the DELETE command:

A

DELETE FROM

WHERE columnX = value

33
Q

What is the PRIMARY KEY keyword used for?

A

Assigning a primary key, or a composite key.

34
Q

Show the syntax of the PRIMARY KEY command:

A

PRIMARY KEY (,) if n is populated a composite key is created.

35
Q

What is the FOREIGN KEY keyword used for?

A

Used to set up a Foreign Key.

36
Q

Show the syntax of the FOREIGN KEY command:

A

FOREIGN KEY REFERENCES ()