SQL commands Flashcards

(35 cards)

1
Q

What is Data Definition Language?

A

it includes SQL commands that create and manipulate database objects such as tables and indexes

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

What is Data Manipulation Language?

A

it includes SQL commands to insert, update read and select data within database tables

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

What is Data Control Language?

A

it includes SQL commands to control who has access to the data of the database

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

Syntax for creating a database

A

create database <database></database>

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

Syntax for creating a schema

A

create schema <schema> AUTHORIZATION <authorization></authorization></schema>

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

Syntax for creating a table

A

create table <[schema name.]table name>(column1 data type [constraints])

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

Syntax for creating an index

A

create [unique] index <index> on <table name>(column1, [column2])</index>

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

What are indexes

A

They are special lookup tables that store selected columns (attributes) and organizes them in an orderly manner such that the retrieval and access of the row instance is more efficient

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

Syntax for making a foreign key in a table

A

foreign key(<column>) references <table name>[(column name)][ ON<update/delete> <action>]</action></column>

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

What is on update no action?

A

when a primary key of a parent table is deleted and the results to any row in the dependent table without a primary key, then the update is rejected

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

What is on delete cascade?

A

if any row instance in the parent table is deleted, then it’s connected dependents are also deleted

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

What is on delete restrict?

A

if any row instance in the parent table is deleted, and its primary key exists as a foreign key in a dependent table, then the delete command will be rejected

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

What is on delete set NULL

A

if any row instance of a parent table is deleted, its foreign keys in dependent tables will be set to NULL

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

What is the check constraint?

A

it is used to limit the value of attributes by giving conditions to the data

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

Syntax that includes a check constraint

A

Area_code char(4) check (area_code in (‘6200’,’6300’))

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

What is the “in” operator?

A

It can be used in place of the “or” operator

17
Q

Syntax for inserting data to table rows

A

insert into <table name>[(column1), (columnN)] values(value1, valueN)

18
Q

Syntax for selecting data from a table row

A

select <column> from <table list> [where <condition>]</condition></column>

19
Q

Syntax for updating table rows

A

update <table name> set <column1> = <expression [, columnN name = <expression>] [where <condition>]</condition></expression></column1>

20
Q

Syntax for deleting table rows

A

delete from <table name>[ where <condition>]</condition>

21
Q

Syntax for inserting data to a table row with select subquery

A

insert into <table name>[(<column_list>)] select <column_list> from <table name></column_list></column_list>

22
Q

What is the “like” special operator?

A

it checks whether an attribute value matches with a given string pattern

23
Q

Syntax that includes a like operator

A

select * from item where itemName like ‘p%’

24
Q

What is the “%a” wild card?

A

searches for characters ending with ‘a’

25
What is the "a%" wild card?
searches for characters starting with 'a'
26
What is the "_" wildcard?
represents exactly one character
27
Syntax for adding a new column to an existing table
alter table add column [column constraint]
28
Syntax for removing a column from an existing table
alter table
drop column
29
Syntax for modifying a column's data type and length
alter table
alter column set data type
30
Syntax for modifying default values
alter table
alter column set default
31
Syntax for renaming a column
alter table
rename column to
32
Syntax for adding a primary key to an existing table
alter table
add primary key()
33
Syntax for adding a foreign key to an existing table
alter table
add foreign key() references
[()] [on update/on delete]
34
Syntax for sorting a list through selecting
select from
[where ][order by [ASC |DESC]]
35