CH 2 - SQL Flashcards

1
Q

SQL

A

structured query language. its the ANSI language use for defintion and manipulation of relational database

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

ddl

A

data definition language. statements that specify and modify database schemas.

e.g
CREATE TABLE
DROP TABLE. removes a table from databse
ALTER TABLE. modifies a table after created
CREATE INDEX

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

dml

A

data manipulation language. statements that manipulate databse content.

eg
INSERT
UPDATE
DELETE

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

facts of sql

A

sql data is case sensitive while commands are not .

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

create table example

A

CREATE TABLE Student (
StudentID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
DateOfBirth DATE,
Gender CHAR(1),
Email VARCHAR(100)
);

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

e.g of alter a table or drop

A

ALTER TABLE Student
ADD PhoneNumber VARCHAR(15);

DROP TABLE Student;
to avoid errors: DROP TABLE IF EXISTS Student;

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

explain the 2 drop options

A

CASCADE : specifies that any foreign key constraint violations that are caused by dropping the table will cause the correspnding rows of the related table to be deleted.

RESTRICT : blocks the deletion of the table of any foreign key constraint violations would be created.

Syntax;
DROP TABLE <table name>[RESTRICT | CASCADE];

learn syntax

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

DML COMMANDS

A

INSERT: adds new rows to tables
UPDATE: modifies one or more attributes
DELETE: deletes one or more rows from a table

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

e.g of instering a row

A

INSERT into<table name>
VALUES(‘value 1’ , ‘value2’ , NULL);

INSERT into FoodCart
VALUES(‘02/08/24’ , ‘ pizza’,’70’)

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

e.g of updating an attribute with sql

A

UPDATE <table name> SET <attr> = <value>
WHERE <selection>;</selection></value></attr>

e.g

UPDATE FoodCart SET sold = 349
WHERE date = ‘02/25/24’ AND food = ‘pizza’;

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

DELETE a row in a table e.g

A

DELETE FROM <Table name>
WHERE <condition>;</condition>

DELETE FROM FoodCart
WHERE food = ‘hotdog’;

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

SQL statement

A

basic SELECT statement includes 3 clauses

SELECT <attribute> FROM <tables> WHERE <condition></condition></tables></attribute>

select specifies the attributes that are part of the resulting relation

FROM = specifies the tables that serve as the input to the statement

WHERE = specifies the selection condition , including the join condition.

// is it possible to use this without WHERE condition?

nb// * in the select statement means that every attribute of the input table is to be selected.

SELECT * FROM …WHERE….;

to get unique rows use DISTINCT keyword after SELECT e.g
SELECT DISTINCT * FROM …
WHERE …;

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

SQL operations

A

join
left join
right join
like

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

sql clauses

A

order by

Group by

Having

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

Join operation

A

its specified as the FROM clause which list the two inut relations and the WHERE clause which lists the join condition

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

e.g of inner join

A

SELECT *
FROM emp join dept
on emp.id = dept.id;

17
Q

left outer join e,g

A

left outer join = left join

SELECT *
FROM emp left join dept
on emp.id = dept.id ;

18
Q

right join e.g

A

right outer join = right join

19
Q
A