3.1.15.1 SQL Query Methods Flashcards

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

What are the 4 query statements?

A
  • DELETE
  • CREATE
  • SELECT
  • UPDATE
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

SQL command for creating a table:

A

CREATE TABLE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
explain what this statement executes:
first_name CHAR (30) NULL,
A
  • CHAR is assigning first_name is a character column (character is basically a string)
  • the (30) in brackets means it will store up to 30 characters in this column
  • NULL means this column (first_name) can be empty
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

why must the key field in a database always have a NOT NULL statement?

A

it must always have a value
for example: key INT IDENTITY (1001, 1) NOT NULL,
) ;

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

explain what this statement executes:
key INT IDENTITY (1001, 1) NOT NULL,
) ;

A
  • this is the key
  • uses the term INT so that it is an integer
  • we want it to start with 1001 and then go up in increments of 1
  • the semi-colon at the end tells the database you’ve finished the command
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is VARCHAR and why is it used?

A

stores a set of alphanumeric data (letters and numbers) as a variable string

  • it is used because it is a variable so will only store the number of characters used (so if the max amount of characters was (80) but only 20 characters were used, it would only allocate 20 spaces)
  • this means is uses less memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

why isn’t always the case that VARCHAR uses less memory space?

A

there could be a minimum length

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

what statement is used to add data?

A

INSERT INTO

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

explain what this statement does:

INSERT INTO Name, ID, DOB VALUES (Jim, NULL, NULL)

A

inserts the value Jim as the name and no values for the ID and DOB

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
explain what this means:
WHERE ID (less than sign and the greater than sign)  10

(wouldn’t let me show it)

A

choose data that is not equal to 10 (less than sign and the greater than sign means not equal to)

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

Key point

A

you must add data in the same given order as the rows in the table. if you don’t know the data for a row, you would assign it to NULL

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

what is the statement to edit/ update data in table?

A

UPDATE

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

what happens if the WHERE clause is left out?

A

all record will be affected (edited)

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

statement for retrieving data:

A

SELECT

SELECT * FROM table1 means select everything in table1

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