SQL Basics Quiz
42 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 the primary purpose of the CREATE statement in SQL?

  • To modify existing database structures
  • To create new database objects (correct)
  • To rename existing database objects
  • To remove data from existing tables
  • Which statement is correct regarding the TRUNCATE command?

  • It renames a database object
  • It deletes the entire database
  • It allows the modification of a table’s columns
  • It removes all data but retains the table structure (correct)
  • What action would you perform with the ALTER statement in SQL?

  • To modify existing database object structures (correct)
  • To delete a database object completely
  • To add comments to a database
  • To create a new database
  • When would you use the RENAME command in SQL?

    <p>To change the name of a database object</p> Signup and view all the answers

    What is the role of the COMMENT command in SQL?

    <p>To add documentation to database objects</p> Signup and view all the answers

    What does SQL stand for?

    <p>Structured Query Language</p> Signup and view all the answers

    Which command is NOT part of SQL's Data Definition Language (DDL)?

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

    Which of the following is a purpose of SQL commands?

    <p>To communicate with the database</p> Signup and view all the answers

    What is the main function of Data Control Language (DCL)?

    <p>To manage user permissions</p> Signup and view all the answers

    Which command is used to permanently remove a table from the database?

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

    What is the role of Data Manipulation Language (DML)?

    <p>To manipulate data in the database</p> Signup and view all the answers

    Which of the following DML commands is used to retrieve data from a database?

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

    Which command would you use to change the structure of an existing database table?

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

    Which data type is classified as an approximate numeric in SQL?

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

    What does the NOT NULL constraint enforce in a SQL database?

    <p>The column cannot hold any NULL values.</p> Signup and view all the answers

    Which constraint uniquely identifies each row in a table?

    <p>Primary Key</p> Signup and view all the answers

    What is the purpose of the CHECK constraint in SQL?

    <p>To ensure values satisfy a specific condition.</p> Signup and view all the answers

    Which SQL data type is specifically used to store binary data?

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

    What does the UNIQUE constraint ensure about the values in a column?

    <p>They must be unique across the entire table.</p> Signup and view all the answers

    For what reason are SQL constraints implemented in a database?

    <p>To limit the types of data going into a table.</p> Signup and view all the answers

    What type of constraint prevents actions that would disrupt the relationships between tables?

    <p>Referential Integrity</p> Signup and view all the answers

    What SQL command would you use to create a new database?

    <p>CREATE DATABASE dbName;</p> Signup and view all the answers

    Which command would you use to remove a specific table from a database?

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

    Which command modifies the structure of an existing table?

    <p>ALTER TABLE table_name;</p> Signup and view all the answers

    In the context of a CREATE TABLE statement, which statement correctly defines a column?

    <p>col_Name varchar(50) NOT NULL;</p> Signup and view all the answers

    What would you do to remove a specific column from an existing table?

    <p>ALTER TABLE table_name DROP COLUMN column_name;</p> Signup and view all the answers

    What is the purpose of the IDENTITY property in a database column?

    <p>It auto-increments the column starting from 1.</p> Signup and view all the answers

    Which statement is correct regarding the definition of a primary key in the CREATE TABLE command?

    <p>A primary key uniquely identifies each record in a table.</p> Signup and view all the answers

    In the CREATE TABLE example, what is the correct data type for the ID column in the second example?

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

    If a column is defined with 'Not Null', what does this imply?

    <p>The column must contain a value for each record.</p> Signup and view all the answers

    Which of the following is a possible data type for the Birth_Date column?

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

    What does the 'Primary key (ID)' statement accomplish in the CREATE TABLE command?

    <p>It designates the ID column as the primary key for the table.</p> Signup and view all the answers

    If a column is defined as 'char(50)', what does this imply about the data it can hold?

    <p>It can hold a maximum of 50 characters.</p> Signup and view all the answers

    What does the term 'auto-increment' specifically refer to concerning database fields?

    <p>Increases the value of a field by 1 for each new entry.</p> Signup and view all the answers

    What is the primary purpose of the DROP command in SQL?

    <p>To remove one or more tables along with their data</p> Signup and view all the answers

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

    <p>ALTER TABLE table_name ADD column_name datatype;</p> Signup and view all the answers

    What does the TRUNCATE command do in SQL?

    <p>Deletes all rows from a table and reclaims its space</p> Signup and view all the answers

    What is the syntax to modify the data type of an existing column using the ALTER command?

    <p>ALTER TABLE table_name MODIFY column_name new_datatype;</p> Signup and view all the answers

    In which scenario would you use the DROP TABLE command?

    <p>To remove the entire structure and data of a table</p> Signup and view all the answers

    Which of the following statements correctly describes the ALTER command?

    <p>It can be used to add, delete, or modify attributes in a table.</p> Signup and view all the answers

    When using the ALTER TABLE command to drop a column, which syntax is correct?

    <p>ALTER TABLE table_name DROP COLUMN column_name;</p> Signup and view all the answers

    What happens to the data in a table after executing the TRUNCATE command?

    <p>The data is deleted permanently</p> Signup and view all the answers

    Study Notes

    Introduction to Databases

    • SQL stands for Structured Query Language.
    • SQL is a standard language used to query and manipulate data.
    • SQL is used to define, create, maintain, and control databases.

    SQL Commands

    • SQL commands are instructions for interacting with databases.
    • SQL commands communicate with the database.
    • SQL commands complete tasks, functions, and queries.
    • SQL can execute various tasks, such as creating tables, inserting data, dropping tables, modifying tables, and setting user permissions.
    • SQL (Structured Query Language) is used to manage records within a database. Operations include updating, inserting, and deleting. It also allows for database table creation and modification.
    • SQL is a query language, not a database system.

    Table Components

    • Tables are structured data collections.
    • Data is organized into records (rows) and fields (columns).
    • Field names define the information in each column.
    • Key fields (sometimes a primary key) uniquely identify each data entry.
    • Data items populate the fields of each record.

    Types of SQL Commands

    • SQL has three main categories of commands: DDL, DML, DCL, TCL.
    • DDL (Data Definition Language): commands to create, alter, drop, and rename objects within a database.
    • DML (Data Manipulation Language): manipulates data within the database using commands like select, insert, update, and delete.
    • DCL (Data Control Language): controls user access and permissions.
    • TCL (Transaction Control Language): manages transactions with commands like commit and rollback.

    Data Definition Language (DDL)

    • DDL is a SQL command type responsible for defining and modifying database objects.
    • DDL commands handle the structure of tables, indexes and views
    • DDL is used by database administrators (DBAs) and developers to manage and maintain database structure.
    • DDL is used in conjunction with DML.

    Common DDL Commands

    • CREATE: Creates new database objects, such as tables, indexes, and stored procedures.
    • ALTER: Modifies existing database objects by adding, deleting, or changing columns in a table.
    • DROP: Deletes database objects.
    • TRUNCATE: Removes all data from a table while maintaining the table structure.
    • RENAME: Changes names of database objects, like tables, columns, and indexes.
    • COMMENT: Adds descriptions or explains database objects.

    Create Database

    • The CREATE DATABASE statement is used to create a new SQL database. -Syntax: CREATE DATABASE databasename;
    • Examples:
    • CREATE DATABASE studentDB;
    • CREATE DATABASE [stores DB];

    Create Table

    • CREATE TABLE is used in databases to create new tables holding data.
    • Syntax: CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPE,....);

    SQL Date Types

    • Data types define the nature of data stored in a column of a table.
    • Common types include alphanumeric, numeric, date, and time. Each data type dictates the kind of information it can store.
    • This includes character strings, numbers, dates, timestamps and other more specialized types like images and XML files

    SQL Constraints

    • Constraints are rules regulating data placed in tables.
    • Used to ensure data integrity, accuracy, and reliability.
    • Constraints are differentiated as column level or table level; column level constraints apply to a column and table constraints apply to the entire table
    • Constraints may be violated resulting in actions being aborted

    Common Constraints in SQL:

    • NOT NULL - ensures a column cannot remain empty (NULL value)

    • CHECK - confirms data conforms to criteria or specific conditions

    • DEFAULT - sets a default value if not provided specifically

    • UNIQUE - guarantees each value in a column is distinct

    • PRIMARY KEY - uniquely identifies each row within a table

    • FOREIGN KEY - links data across multiple tables, preventing data inconsistencies

    • IDENTITY: a column auto-increments from 1

    Data Table Examples

    • Sample table schemas and structures are presented.

    Database Diagrams

    • Visual diagrams illustrating the relationships between various database tables are shown.

    Drop Command

    • Removes tables or entire databases. -Removes table structure AND all data contained within (or data structure). -Syntax: DROP DATABASE databasename;
      • DROP TABLE table_name;

    ALTER Command

    • Modifies the structure of an existing table. -Used to add or alter table columns or constraints.
      • Used to modify the characteristics of existing attributes in tables.
      • Can add, remove or change columns. -Syntax:
      • ALTER TABLE table_name ADD column_name datatype;
      • ALTER TABLE table_name DROP COLUMN column_name;
      • ALTER TABLE table_name ALTER COLUMN column name DATATYPE;

    Truncate Command

    • Deletes all rows within a table, freeing up storage space.
    • Does not alter the structure.
    • Syntax: TRUNCATE TABLE table_name;

    DDL Examples

    • Examples demonstrating the use of DDL commands for creating and managing databases and tables were provided.

    Database Design Assignments

    • Presents scenarios for database design and their associated table structures. Several design assignments are provided, including hospital, airport, and student information databases. Each offers specific attributes and relationships to define.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    SQL and DDL PDF

    Description

    Test your knowledge of SQL commands and their functions with this quiz. Questions cover essential components like CREATE, TRUNCATE, ALTER, and more. Perfect for beginners who want to strengthen their understanding of SQL concepts and language.

    More Like This

    SQL Commands Quiz
    3 questions

    SQL Commands Quiz

    EminentCelebration avatar
    EminentCelebration
    Introduction to SQL Commands
    9 questions

    Introduction to SQL Commands

    FascinatingCornflower avatar
    FascinatingCornflower
    Lenguaje SQL y Álgebra Relacional
    21 questions
    Use Quizgecko on...
    Browser
    Browser