Quiz 2 - SQL/Create Database Flashcards

1
Q

SQL: CREATE TABLE syntax

A
CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
...
);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

SQL: CREATE TABLE syntax - w/constraints

A

CREATE TABLE table_name
(
column_name1 data_type(size) constraint_name,
column_name2 data_type(size) constraint_name,
column_name3 data_type(size) constraint_name,
….
);

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

SQL: ALTER TABLE syntax - add column

A

ALTER TABLE table_name
ADD COLUMN column_name datatype
;

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

SQL: ALTER TABLE syntax - drop column

A

ALTER TABLE table_name
DROP COLUMN column_name
;

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

SQL: ALTER TABLE syntax - change datatype

A

ALTER TABLE table_name
ALTER COLUMN column_name datatype
;

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

SQL: ALTER TABLE syntax - add constraint

A

ALTER TABLE table_name
ADD CONSTRAINT constraint_name constraint_keyword (column_name)
;

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

Constraint Keywords

A
  • NOT NULL
  • UNIQUE
  • PRIMARY KEY
  • FOREIGN KEY
  • CHECK
  • DEFAULT
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

SQL: ALTER TABLE syntax - add Foreign Key

A
ALTER TABLE Orders
ADD CONSTRAINT fk_PerOrders
FOREIGN KEY (P_Id)
REFERENCES Persons(P_Id)
;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

SQL: ALTER TABLE syntax - add CHECK

A

ALTER TABLE Persons
ADD CONSTRAINT chk_Person CHECK (P_Id>0)
;

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

SQL: ALTER TABLE syntax - add DEFAULT

A

ALTER TABLE Persons
ALTER COLUMN City SET DEFAULT ‘Fairfax’
;

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