SQL Fundamentals
22 Questions
2 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is a primary key defined through?

  • Relationship
  • Constraint (correct)
  • Attribute
  • Entity
  • What are foreign keys also defined as?

  • Constraint (correct)
  • Attribute
  • Entity
  • Relationship
  • 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?

    <p>They must be not null and unique</p> Signup and view all the answers

    How are many-to-many relationships represented in a database?

    <p>As two many-to-one relationships</p> Signup and view all the answers

    What SQL command is used to delete a table?

    <p>DROP TABLE</p> Signup and view all the answers

    What is used to define a foreign key?

    <p>The columns which make up the FK, the referenced table, and the columns which are referenced by the FK</p> Signup and view all the answers

    What happens to attributes in a database?

    <p>They become columns with the same name</p> Signup and view all the answers

    What is the purpose of the DROP TABLE command?

    <p>To remove a table from the database</p> Signup and view all the answers

    Which command is used to add a new column to a table?

    <p>ALTER TABLE r ADD A D</p> Signup and view all the answers

    What is the purpose of the UPDATE command?

    <p>To change row(s) in a table</p> Signup and view all the answers

    What is the use of the WHERE clause in UPDATE and DELETE commands?

    <p>To specify which rows to change or remove</p> Signup and view all the answers

    What is the command to add a constraint to a table?

    <p>ALTER TABLE r ADD CONSTRAINT</p> Signup and view all the answers

    What is the command to delete all tuples from a table?

    <p>DELETE FROM r</p> Signup and view all the answers

    What was SQL originally called?

    <p>Sequel</p> Signup and view all the answers

    Which of the following SQL data types is a fixed-length character string?

    <p>char(n)</p> Signup and view all the answers

    What is the purpose of the create table command in SQL?

    <p>To define an SQL relation</p> Signup and view all the answers

    What is the primary purpose of integrity constraints in SQL?

    <p>To restrict the set of allowed values for an attribute</p> Signup and view all the answers

    What is the name of the standard that most modern DBMS use in SQL?

    <p>SQL-92</p> Signup and view all the answers

    What is the data type of the attribute 'budget' in the 'department' table?

    <p>numeric(12,2)</p> Signup and view all the answers

    What is the purpose of the 'primary key' constraint in SQL?

    <p>To specify a unique identifier for a table</p> Signup and view all the answers

    In which year was SQL-86 standard introduced?

    <p>1986</p> Signup and view all the answers

    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;

    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.

    Quiz Team

    Description

    This quiz covers the basics of SQL, including data types, schema definition, integrity constraints, and E-R designs. It also explores the history of SQL and its development.

    More Like This

    Structured Query Language (SQL) Overview
    10 questions
    Câu hỏi về Cơ Sở Dữ Liệu
    18 questions
    Introduzione a SQL e la sua Storia
    40 questions
    Use Quizgecko on...
    Browser
    Browser