Structured query langauge (SQL) Flashcards

1
Q

What is SQL?

A

‘Structured Query Language’, that can do data definition, management, access control, and queries as well as control flow.

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

Is SQL declarative or procedural?

A

It is declarative even though it also includes some procedural elements.

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

How many values does BOOLEAN have

A

3:

TRUE, FALSE, UNKOWN (accounts for null)

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

How can you check if a value is null in SQL?

A

IS NULL and IS NOT NULL

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

How do you check the length of a char in a column?

A

SELECT CHAR_LENGTH(“Philiong”) AS LengthOfString;

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

which methods can you use when dealing with dates?

A

CURRENT_TIME, CURRENT_DATE, CURRENT_TIMESTAMP

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

How do you specify that an attribute may not be null?

A

add the: NOT NULL constraint

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

How do you define a default value to an attribute?

A

when you define an attribute add the clause DEFAULT to the attribute definition.

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

What value will an attribute be given if no value or default is provided?

A

NULL

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

How can you make sure that an added value is between a certain range?
(When declaring an attribute for a table with a statement)

A

add the CHECK keyword to a definition like this : age INT NOT NULL CHECK (age > 0 AND age < 121)

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

What is the default action that SQL uses for referential integrity?

A

NO ACTION

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

What does the NO ACTION referential integrity do

A

It rejects the operation if it will cause a violation

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

How can you get around the NO ACTION rejection?

A

You can attach a triggered action on any foreign key constraint like SET NULL, CASCADE and SET DEFAULT that can trigger on the ON DELETE or ON UPDATE

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

What is an ASSERTION?

A

It is a check that can involve multiple tables.

e.g:
CREATE ASSERTION MaxNumberOfEmployee CHECK (NOT EXISTS (SELECT Eid
FROM Employee
GROUP BY Eid
HAVING COUNT(*) > 20))
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the schema do in a database system?

A

It defines tables, relationships and the fields of the tables.

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

What is the syntax for creating a database?

A

CREATE DATABASE IF NOT EXISTS database_name

17
Q

What is the syntax for creating tables?

A

CREATE TABLE Employee

18
Q

What is the syntax for deleting tables?

A

DROP TABLE IF EXISTS Employee

19
Q

What is the syntax for changing tables?

A

ALTER TABLE Employee

ADD last_name VarChar(20 NOT NULL)

20
Q

What are the commands for

  1. retrieving data
  2. inserting data
  3. updating data
  4. deleting data
A
  1. select
  2. insert
  3. update
  4. delete
21
Q

What is the syntax for retrieving data?

A

SELECT (DISTINCT | ALL ) ( * | Attribute) (AS newName)
FROM tableName
WHERE condition

22
Q

How can you make aliases in SQL?

A

SELECT Name AS FirstName

FROM Employee e

23
Q

How can you insert?

A

INSERT is used to add a single row to a table

INSERT INTO EMPLOYEE (Fname, Ssn) VALUES (‘Andrea’, ‘1234’);

24
Q

How can you delete?

A

DELETE FROM table_name WHERE

only DELETE FROM table_name all records will be deleted

25
How can you update?
UPDATE Employee SET Salary = Salary * 1.1 WHERE Dno = 5;