Are you a second-year Computer Science student at the University of Cape Town looking for a comprehensive study aid to excel in your practicals, tests, and exams? Look no further! These meticulously crafted digital lecture notes cover databases.
Insert:
INSERT INTO <TableName>
VALUES (<Col1Value>, <Col2Value>, ... , <ColnValue>);
Insert (Nested): Data Types:
INSERT INTO <TableName> INTEGER, FLOAT,
VALUES (<SelectQuery>); ENUM(v,v,v,v,v), DOUBLE, REAL,
NUMERIC, BIT, VARCHAR, DATE
Table Creation: etc. (see slides)
CREATE TABLE <NewTableName> Null Handling:
NULL -> Allows Null Values
(<Col1Name> <DataType> <NullHandling>,
NOT NULL -> No Null Values
<Col2Name> <DataType> <NullHandling>,
...
<ColnName> <DataType> <NullHandling>,
PRIMARY KEY (<ColiName>, ... ,<ColjName>),
CHECK (<ColiName> IN (<SelectQueryOnPKeyOrigin>))
CHECK (<ColjName> IN (<SelectQueryOnPKeyOrigin>))
);
Retrieve:
Select Specific Columns of Row:
SELECT <Col1Name>, ... ,<ColnName>
FROM <TableName>;
Select All Columns of Row:
SELECT *
FROM <TableName>;
Select Ordered (Ascending):
SELECT <ColiName>
FROM <TableName>
ORDER BY <Col1Name>, ... ,<ColnName>;
Select Ordered (Descending):
SELECT <ColiName>
FROM <TableName>
ORDER BY <Col1Name>, ... ,<ColnName> DESC;
Select By Logical Condition:
SELECT <ColiName>
2
, BEN FROST
FROM <TableName>
WHERE <LogicalCondition>;
Logical Condition Configurations:
Standard Comparison:
WHERE <ColiName> = | <= | >= | < | > <Value>;
Starts With:
WHERE <ColiName> LIKE “<Value>%”;
Ends With: _ -> One Char Wildcard
WHERE <ColiName> LIKE “%<Value>”;
Contains:
WHERE <ColiName> LIKE “%<Value>%”;
&&:
WHERE <Logical1Condition> AND <Logical2Condition>;
||:
WHERE <Logical1Condition> OR <Logical2Condition>;
!:
WHERE NOT <LogicalCondition>;
Between:
WHERE <ColiName> BETWEEN <LowerBound> AND <UpperBound>;
Null/Not Null:
WHERE <ColiName> IS NULL; | WHERE <ColiName> IS NOT NULL;
Select Distinct Row:
SELECT DISTINCT <Col1Name>, ... ,<ColnName>
FROM <TableName>;
Select Top n Ordered Rows:
SELECT TOP <Value> <Col1Name>, ... ,<ColnName>
FROM <TableName>
ORDER BY <Col1Name>, ... ,<ColnName>;
, BEN FROST
-
Set Theory:
Union:
<SelectedSet> UNION <SelectedSet> Set functions all retain
Intersect: duplicates. Selected
<SelectedSet> INTERSECT <SelectedSet> relations’ structures must
match.
Except:
<SelectedSet> EXCEPT <SelectedSet>
Number Functions:
Substring From Left:
LEFT(<String>,<NumberOfChars>)
Substring From Right:
RIGHT(<String>,<NumberOfChars>)
Substring From Middle (to Right):
MID(<String>, <StartPosition> ,<NumberOfChars>)
COALESCE Function: COALESCE takes the first non-NULL
COALESCE(<Col1Name>, ... ,<ColnName>) value of the specified columns. (in order)
Deriving Functions As New Output Columns:
SELECT <FunctionOnTable> AS <NewColumnName>
FROM <TableName>;
4
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller benfro764. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $2.99. You're not tied to anything after your purchase.