Chapter 19 - Defining and updating tables by using SQL Flashcards

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

What are the commands to create a new table in the SQL?

A

» CREATE TABLE (tablename)
{
Column1 Data type,etc
Column2 Data type,etc
Column3 Data type, etc
}

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

What is the purpose of the NOT NULL statement?

A

» If you put it in when you create a new table, it is a compulsory field

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

What is the purpose of the PRIMARY KEY statement?

A

» States the column is the primary key

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

What is the purpose the CHAR(n) data type?

A

» Makes sure the data entered character’s are a fixed length of, n

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

What is the purpose of the VARCHAR(n) data type?

A

» Makes sure the data entered has a character string variable of max length, n

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

What is the purpose the BOOLEAN data type?

A

» Make sure the data entered is TRUE or FALSE

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

What is the purpose of the INTEGER data type?

A

» Makes sure the data entered is an integer

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

What is another way to write the INTEGER data type?

A

» INT

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

What is the purpose of the FLOAT data type?

A

» Make sure it is a number with a floating decimal point

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

What does it mean by the FLOAT(X,Y) command?

A

» X - Maximum number of digits is X
» Y - Maximum number after decimal point is Y

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

What does the DATE data type do?

A

» Stores the data entered as Day,Month,Year values

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

What is the purpose of the TIME data type?

A

» Stores the data entered as Hour,Minute,Second values

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

What does the CURRENCY data type do?

A

» Formats numbers in the currency used in your region

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

What does the CURRENCY data type do?

A

» Formats numbers in the currency used in your region

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

What is the purpose of the ALTER TABLE statement?

A

» To add, delete or modify columns in an exisiting table

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

What is the SQL commands to add a column?

A

ALTER TABLE (tablename)
ADD COLUMN DATATYPE

17
Q

What is the SQL command do delete a column?

A

ALTER TABLE (tablename)
DROP COLUMN (columname)

18
Q

What is the SQL command to change the data type of a column?

A

ALTER TABLE (tablename)
MODIFY COLUMN (columname) …. DATATYPE you want to modify

19
Q

What are the steps to create a linked table

A

CREATE TABLE (tablename)
{
Column1
Column2 … DATATYPE
FOREIGN KEY COLUMN REFERENCE X
FOREIGN KEY COLUMN REFERENCE Y
PRIMARY KEY (FOREIGN KEY, FOREIGN KEY)
}
» Note X and Y are where the foreign key originally came from, e.g for a foreign key called COURSEID which came from Course, X would look like Course(COURESEID)

20
Q

What is the SQL statement to insert a new record in a database table?

A

INSERT INTO tablename(column1,column2)
VALUES (value1,value2…)
……….

21
Q

What is some tips to remember about the stuff in brackets in VALUES (value1…)?

A

» Everything should be seperated by a comma
» Speech marks for all the strings inserted
» Apart from CURRENCY and Date
» Data has the syntax #day/month/year#
» Currency does not need anything else

22
Q

What would be a more efficient way of inserting data, when all the fields are being added in the correct order?

A

» You would not need fields names in the INSERT statement
» INSERT INTO tablename - would be enough

23
Q

What is the SQL statement to update a record in a database table?

A

UPDATE tablename
SET column1 = value1, column 2 =value2…..
WHERE ColumnX = value
» Example:
UPDATE EMPLOYEE
SET SALARY = SALARY*1.1
WHERE DEPARTMENT = “TECHNICAL”

24
Q

What is the SQL statement to delete a record from a database table?

A

DELETE FROM tablename
WHERE columnx = value
» Example:
DELETE FROM EMPLOYEE
WHERE EmpID = “1122”

25
Q

What does the DROP TABLE tablename command do?

A

» Can be used to drop an existing table in a database