3.1.15.1 SQL Query Methods Flashcards
What are the 4 query statements?
- DELETE
- CREATE
- SELECT
- UPDATE
SQL command for creating a table:
CREATE TABLE
explain what this statement executes: first_name CHAR (30) NULL,
- 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
why must the key field in a database always have a NOT NULL statement?
it must always have a value
for example: key INT IDENTITY (1001, 1) NOT NULL,
) ;
explain what this statement executes:
key INT IDENTITY (1001, 1) NOT NULL,
) ;
- 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
what is VARCHAR and why is it used?
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
why isn’t always the case that VARCHAR uses less memory space?
there could be a minimum length
what statement is used to add data?
INSERT INTO
explain what this statement does:
INSERT INTO Name, ID, DOB VALUES (Jim, NULL, NULL)
inserts the value Jim as the name and no values for the ID and DOB
explain what this means: WHERE ID (less than sign and the greater than sign) 10
(wouldn’t let me show it)
choose data that is not equal to 10 (less than sign and the greater than sign means not equal to)
Key point
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
what is the statement to edit/ update data in table?
UPDATE
what happens if the WHERE clause is left out?
all record will be affected (edited)
statement for retrieving data:
SELECT
SELECT * FROM table1 means select everything in table1