Podcast
Questions and Answers
What is a primary key defined through?
What is a primary key defined through?
- Relationship
- Constraint (correct)
- Attribute
- Entity
What are foreign keys also defined as?
What are foreign keys also defined as?
- Constraint (correct)
- Attribute
- Entity
- Relationship
What happens to entities in a database?
What happens to entities in a database?
- They become tables (correct)
- They become attributes
- They become constraints
- They become relationships
What is required of primary key attributes?
What is required of primary key attributes?
How are many-to-many relationships represented in a database?
How are many-to-many relationships represented in a database?
What SQL command is used to delete a table?
What SQL command is used to delete a table?
What is used to define a foreign key?
What is used to define a foreign key?
What happens to attributes in a database?
What happens to attributes in a database?
What is the purpose of the DROP TABLE command?
What is the purpose of the DROP TABLE command?
Which command is used to add a new column to a table?
Which command is used to add a new column to a table?
What is the purpose of the UPDATE command?
What is the purpose of the UPDATE command?
What is the use of the WHERE clause in UPDATE and DELETE commands?
What is the use of the WHERE clause in UPDATE and DELETE commands?
What is the command to add a constraint to a table?
What is the command to add a constraint to a table?
What is the command to delete all tuples from a table?
What is the command to delete all tuples from a table?
What was SQL originally called?
What was SQL originally called?
Which of the following SQL data types is a fixed-length character string?
Which of the following SQL data types is a fixed-length character string?
What is the purpose of the create table command in SQL?
What is the purpose of the create table command in SQL?
What is the primary purpose of integrity constraints in SQL?
What is the primary purpose of integrity constraints in SQL?
What is the name of the standard that most modern DBMS use in SQL?
What is the name of the standard that most modern DBMS use in SQL?
What is the data type of the attribute 'budget' in the 'department' table?
What is the data type of the attribute 'budget' in the 'department' table?
What is the purpose of the 'primary key' constraint in SQL?
What is the purpose of the 'primary key' constraint in SQL?
In which year was SQL-86 standard introduced?
In which year was SQL-86 standard introduced?
Flashcards are hidden until you start studying
Study Notes
Overview to SQL
- Originally called 'Sequel', Structured English Query Language
- Designed and implemented at IBM, with ANSI Standards: SQL-86 or SQL1, SQL-92 or SQL2, SQL-99 or SQL3
- Most modern DBMS use a variety of SQL, mostly based on SQL2, increasingly SQL3
- Can be used from other languages and often extended to provide common programming constructs (if-then tests, loops, variables, etc.)
SQL Data Types
- char(n): fixed-length character string
- varchar(n): variable-length character string with specific maximum length n
- int: integer
- smallint: small integer
- numeric(p, d): fixed-point number with user-specified precision
- float(n): floating-point number, with precision of at least n digits
- real, double precision
SQL Basic Schema Definition
- Defines an SQL relation using the create table command
- General form:
create table r (A1 D1, A2 D2, ..., An Dn, ...);
- r is the name of the relation, Ai is the name of an attribute, Di specifies the type of attribute Ai
Integrity Constraints
- SQL prevents updates that violate an integrity constraint
- Supports various integrity constraints, including:
- Primary key: primary key attributes are required to be not null and unique
- Foreign key: defined through constraints, specifying columns, referenced table, and referenced columns
Implementing E/R Designs
- Entities and attributes: each entity becomes a table, with attributes as columns
- Primary keys are defined through constraints
- Relationships:
- 1:1: usually not used or treated as a special case of M:1
- M:1: represented as a foreign key from the M-side to the 1
- M:M: split into two M:1 relationships
Example
- Creating tables for department, course, and instructor entities
- Defining primary keys and foreign keys
More SQL
- DROP TABLE: deletes a table
- ALTER TABLE: changes a table
- Adds or removes a column
- Adds or removes a constraint
- INSERT, UPDATE, and DELETE: add, change, or remove rows from a table
- Use WHERE clauses to specify which rows to change or remove
- Be careful with these, as incorrect WHERE clauses can destroy data
Deleting Tables
- DROP TABLE removes a table
- DELETE FROM removes all tuples from a table
Changing Tables
- ALTER TABLE:
- Adds a new column:
alter table r add A D;
- Removes an existing column:
alter table r drop A;
- Adds a new constraint:
alter table r add constraint;
- Removes an existing constraint:
alter table r drop constraint;
- Adds a new column:
INSERT and UPDATE
- INSERT INTO: adds a row to a table
- UPDATE: changes row(s) in a table
- Both use WHERE clauses to specify which rows to change or add
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.