SQL
No description yet. This curated deck is ready for daily study.
Card preview (19)
What does sql stand for?
Structured Query Language
What are the advantages of using SQL?
It’s easy to learn and use (as it’s a declarative language)
What are the 5 main SQL commands and what are the used for?
CREATE - used for creating tables SELECT - used for retrieving data from a table UPDATE - used for changing an attribute in an existing record INSERT - used for DELETE - used for removing records from a table
What is the format for a SELECT command?
SELECT attributes FROM table WHERE condition ORDER BY asc/desc
What is the format for a UPDATE command?
UPDATE table (attributes) SET new values WHERE = condition
What is the format for a DELETE command?
DELETE attributes FROM table WHERE condition
What is the format for a INSERT command that inserts values into all columns?
INSERT INTO table VALUES (value1, value2, …)
What is the format for a INSERT command that inserts values into specific columns?
INSERT INTO tablename (column1, column2) VALUES (value1, value2, …)
What does SELECT * FROM …. mean and what is the special name for it?
• It means select all the attributes from the database that apply to the condition. • The asterix (select all) is called a wildcard
What is the format for a CREATE command that inserts values into specific columns?
CREATE TABLE ( VARCHAR(225), VARCHAR(255), YEAR, PRIMARY KEY ( , ))
How is a fixed length string data type represented?
CHAR(size) - A string with the number of characters specified by size
How is a variable length string data type represented?
VARCHAR(size) - A string with any number of characters up to the number specified by size
How is a Integer data type represented?
INT(size) - Stores a whole number using the number of bits specified by size
How is a Number with fractional part data type represented?
FLOAT(size, precision) - A number stored using the number of bits specified by size with digits after the decimal point up to the number specified by precision
How is a Date data type represented?
DATE - A date in the format YYYY-MM-DD
How is a Date and time data type represented?
DATETIME - A date and time combined in the format YYYY-MM-DD HH:MM:SS
How is a Time data type represented?
TIME - A time in the format HH:MM:SS
How is a Year data type represented?
YEAR - A year in one of the two formats YY or YYYY
What is the format for an ALTER command?
To add a column: ALTER TABLE Employee ADD Department VARCHAR(10) To delete a column: ALTER TABLE Employee DROP COLUMN HireDate To change a column data type: ALTER TABLE Employee MODIFY COLUMN EmpName VARCHAR(30) NOT NULL