CompTIA DataSys+ (DS0-001)Database FundamentalsEasy
A database developer is writing a script to create a new table called `AuditLog` that will record every user login attempt. This table needs to store the `LoginTime` (timestamp), `UserID` (integer), `IPAddress` (string), and `Success` (boolean). Which SQL DDL statement correctly defines this table structure?
- ACREATE TABLE AuditLog (LoginTime DATETIME, UserID INT, IPAddress VARCHAR(15), Success BOOLEAN);
- BALTER TABLE AuditLog ADD COLUMN LoginTime DATETIME;
- CINSERT INTO AuditLog (LoginTime, UserID, IPAddress, Success) VALUES (NOW(), 123, '192.168.1.1', TRUE);
- DSELECT LoginTime, UserID FROM AuditLog WHERE Success = TRUE;
Show answer & explanationAnswer & explanation
Correct answer: A. CREATE TABLE AuditLog (LoginTime DATETIME, UserID INT, IPAddress VARCHAR(15), Success BOOLEAN);
The `CREATE TABLE` statement is used to define a new table in the database, specifying its name and the columns it will contain, along with their data types. Option A correctly uses `CREATE TABLE` with appropriate data types for the given requirements.
Why the other options are wrong
- B. This is an `ALTER TABLE` statement (DDL), used to modify an existing table, not create a new one.
- C. This is an `INSERT` statement (DML), used to add data to an existing table, not create its structure.
- D. This is a `SELECT` statement (DML), used to retrieve data from a table, not create its structure.
CREATE TABLE Statement
A SQL DDL (Data Definition Language) command used to define and create a new table in a database.
- Specifies the table name and column definitions (name, data type, constraints).
- Forms the basic structure for storing data in a relational database.
- Part of the DDL set of SQL commands.
Memory trick: DDL: 'Define' 'Data' 'L'ayout.