6 SQL Flashcards
(53 cards)
What is SQL?
SQL is the language used to talk to databases.
What are the two main types of SQL statements?
- DDL - Data Definition Language
- DML - Data Manipulation Language
In SQL, what is a table referred to as?
Relation
In SQL, what is a row referred to as?
Tuple
In SQL, what is a column referred to as?
Attribute
What does an SQL schema include?
- Schema name
- User (account) who owns the schema (authorization identifier)
- List of descriptions of what is inside (tables, views, etc)
How do you create an SQL schema named Company owned by user Fury?
CREATE SCHEMA Company AUTHORIZATION Fury;
What is a catalog in SQL?
A named collection of schemas in an SQL environment.
How to create a new table called employee inside the SQL schema called company?
CREATE TABLE Company.EMPLOYEE(
* FName VARCHAR(15) NOT NULL,
* LName VARCHAR(15) NOT NULL,
* SSN CHAR(10) NOT NULL,
* NIE CHAR(10) NOT NULL,
* BDate DATE,
* Address VARCHAR(30),
* Salary DECIMAL,
* BossSSN CHAR(10),
* NumDept INT NOT NULL,
PRIMARY KEY (SSN),
UNIQUE (NIE),
FOREIGN KEY (NumDept) REFERENCES DEPARTMENT(DNumber),
FOREIGN KEY (BossSSN) REFERENCES EMPLOYEE(SSN)
);
What does the UNIQUE constraint do in SQL?
Defines an alternate key.
What does VARCHAR mean in SQL?
Adjusts to actual number of characters but max number is set in ().
What does CHAR mean in SQL?
Fixed number of characters, will be that number even if they use less.
What does DECIMAL mean in SQL?
Stores numbers with fixed digits before and after the decimal.
What does DATE mean in SQL?
Stores calendar dates in the format YYYY-MM-DD.
What does INT mean in SQL?
Whole number, no decimals, commonly used for counting.
What does NOT NULL mean in SQL?
Column must have value, can’t be left empty.
How do you create a custom domain in SQL?
CREATE DOMAIN SSN-TYPE AS CHAR(10);
How can you reuse a custom domain in SQL?
SSN SSN-TYPE; instead of SSN CHAR(10).
What are SQL clauses?
Parts of an SQL query, e.g. SELECT and FROM.
What does the SELECT clause do in an SQL query?
Specifies the list of attribute (column) names to be retrieved.
What does the FROM clause do in an SQL query?
Specifies the list of relation (table) names necessary to process the query.
What does the WHERE clause do in an SQL query?
Specifies a Boolean expression.
What is prefixing in SQL?
Putting the table name before the column name, e.g. DEPARTMENT.Number.
What are aliases in SQL?
Temporary names for columns or tables used to make output or query easier to read or write