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 (A)</p> Signup and view all the answers

What is the role of the COMMENT command in SQL?

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

What does SQL stand for?

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

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

<p>INSERT (A)</p> Signup and view all the answers

Which of the following is a purpose of SQL commands?

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

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

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

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

<p>DROP (A)</p> Signup and view all the answers

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

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

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

<p>SELECT (B)</p> Signup and view all the answers

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

<p>ALTER (D)</p> Signup and view all the answers

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

<p>float (B)</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. (B)</p> Signup and view all the answers

Which constraint uniquely identifies each row in a table?

<p>Primary Key (C)</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. (A)</p> Signup and view all the answers

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

<p>Image (A)</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. (B)</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. (B)</p> Signup and view all the answers

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

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

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

<p>CREATE DATABASE dbName; (C)</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; (D)</p> Signup and view all the answers

Which command modifies the structure of an existing table?

<p>ALTER TABLE table_name; (C)</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; (A)</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; (A)</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. (C)</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. (D)</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 (D)</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. (A)</p> Signup and view all the answers

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

<p>date (A)</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. (B)</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. (A)</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. (A)</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 (D)</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; (C)</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 (D)</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; (D)</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 (C)</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. (B)</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; (A)</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 (B)</p> Signup and view all the answers

Flashcards

What is SQL?

SQL stands for Structured Query Language. It's the language used to communicate with and manage databases.

What are SQL Commands?

SQL commands are instructions used to interact with a database. They allow you to create tables, add data, modify and delete information, and control user access.

What is a Table?

A table is a structured set of data, organized into rows and columns. It's the fundamental way data is stored in a relational database.

What is DDL?

Data Definition Language (DDL) is a set of SQL commands used to define and modify the structure of a database, including creating, altering, and deleting tables, indexes, and views.

Signup and view all the flashcards

Who uses DDL?

DDL commands allow database administrators and developers to manage the overall structure of the database. They ensure that the database is well-organized and ready to store data.

Signup and view all the flashcards

What is DML?

Data Manipulation Language (DML) is a set of SQL commands used to manipulate data within a database. This includes adding, updating, deleting, and retrieving data from tables.

Signup and view all the flashcards

What is DCL?

Data Control Language (DCL) is a set of SQL commands used to control access to the database, including granting and revoking permissions to users.

Signup and view all the flashcards

What is TCL?

Transaction Control Language (TCL) is a set of SQL commands used to manage transactions, ensuring that data changes are applied consistently and reliably.

Signup and view all the flashcards

CREATE

A command used to create new database objects such as tables, indexes, views, and stored procedures.

Signup and view all the flashcards

ALTER

A command used to modify the structure of existing database objects, such as adding, deleting or modifying columns in a table.

Signup and view all the flashcards

DROP

A command used to delete entire database objects or parts of them, such as deleting a table or a column in a table.

Signup and view all the flashcards

TRUNCATE

A command used to remove all the data from a table but keep its structure.

Signup and view all the flashcards

RENAME

A command used to rename an existing database object such as a table, column, or index.

Signup and view all the flashcards

SQL Constraints

A set of rules that define the structure and integrity of data within a table.

Signup and view all the flashcards

NOT NULL Constraint

Ensures that a column cannot be left empty. It must always have a value.

Signup and view all the flashcards

CHECK Constraint

Verifies that the data in a column complies with a specific rule or condition.

Signup and view all the flashcards

Default Constraint

Sets a predefined value for a column if no value is explicitly provided.

Signup and view all the flashcards

UNIQUE Constraint

Guarantees that all values in a column are distinct and unique.

Signup and view all the flashcards

PRIMARY KEY Constraint

A combination of UNIQUE and NOT NULL that acts as a primary identifier for each row in a table.

Signup and view all the flashcards

Referential Integrity (FK)

Maintains data consistency by linking tables together and preventing actions that would break those links.

Signup and view all the flashcards

FOREIGN KEY Constraint

A type of constraint that links a column in one table to the primary key of another table, ensuring data consistency.

Signup and view all the flashcards

What does the DROP command do?

The DROP command removes one or more table definitions and all data associated with them. It's like erasing a table entirely, including its structure and the information it holds.

Signup and view all the flashcards

What is DROP DATABASE used for?

The DROP DATABASE command removes an entire database, including all tables and data stored within it.

Signup and view all the flashcards

What's the purpose of DROP TABLE?

The DROP TABLE command specifically focuses on removing a single table. It deletes the table's structure and all the data it contained.

Signup and view all the flashcards

Describe the purpose of the ALTER command?

The ALTER command is used to change the structure of a database or table. With it, you can add or remove columns, modify data types, and add constraints.

Signup and view all the flashcards

How do you add a new column to a table using ALTER?

The ALTER TABLE ... ADD syntax allows you to add a new column to an existing table. It's like creating a new room in your house.

Signup and view all the flashcards

How do you remove a column from a table with ALTER?

The ALTER TABLE ... DROP COLUMN syntax removes an existing column from a table. It's like removing a room or feature from a house.

Signup and view all the flashcards

What is ALTER TABLE ... ALTER COLUMN used for?

The ALTER TABLE ... ALTER COLUMN syntax allows you to change the data type or modify existing properties of a column within a table.

Signup and view all the flashcards

What does the TRUNCATE command do?

The TRUNCATE command removes all the data from a table, leaving its structure intact. It's like emptying a storage container but keeping the container itself.

Signup and view all the flashcards

What is the 'IDENTITY' property in SQL?

The IDENTITY property automatically generates a unique, sequential number for each new row inserted into a column. It's like having a built-in counter that starts at 1 and increases with each new entry.

Signup and view all the flashcards

What data type requirement is there for the IDENTITY property?

To use the IDENTITY property, the data type of the column must be an integer. Integers are whole numbers, and they work perfectly with the auto-incrementing nature of IDENTITY.

Signup and view all the flashcards

How do you use IDENTITY in SQL?

When you create a new table, you can specify that a column should have the IDENTITY property by using the IDENTITY(seed, step) clause. 'Seed' is the starting value (usually 1), and 'step' determines how much the value increases with each new row (usually 1).

Signup and view all the flashcards

What are SQL Constraints?

SQL Constraints are rules that enforce data integrity and consistency in a database. They ensure that your data remains valid and reliable, preventing errors and invalid entries.

Signup and view all the flashcards

What is a 'Primary Key' constraint?

A Primary Key constraint ensures that each row in a table has a unique identifier. It helps to distinguish different records and find information efficiently.

Signup and view all the flashcards

What is the 'NOT NULL' constraint?

The NOT NULL constraint ensures that a column cannot have any empty values. This ensures that all entries are complete and contain relevant information.

Signup and view all the flashcards

What is DDL (Data Definition Language) in SQL?

DDL (Data Definition Language) is a subset of SQL used to define and modify the structure of a database. It's like the architect who designs the layout and framework of the database.

Signup and view all the flashcards

What is DML (Data Manipulation Language) in SQL?

DML (Data Manipulation Language) is a subset of SQL used to add, modify, or delete data within a database. It's like the librarian who manages the information stored in the database.

Signup and view all the flashcards

What is DDL (Data Definition Language)?

A set of SQL commands used to define and modify the structure of a database, including creating, altering, and deleting tables, indexes, and views.

Signup and view all the flashcards

What does the CREATE command do?

This command is for building new database objects. Imagine you're constructing a building - you use CREATE to lay down the foundation and define the rooms (tables, views, etc.).

Signup and view all the flashcards

What does the ALTER command do?

This command modifies the structure of existing database objects. Picture yourself making changes to your building - adding a new room or changing the size of a window.

Signup and view all the flashcards

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
SQL JOIN commands
19 questions

SQL JOIN commands

IngenuousSupernova5349 avatar
IngenuousSupernova5349
Use Quizgecko on...
Browser
Browser