SQL and Database Concepts: Questions and Answers
What is SQL?
SQL (Structured Query Language) is a programming language used to manage and manipulate
relational databases.
What is MySQL?
MySQL is an open-source relational database management system (RDBMS) that uses SQL as its
query language.
What are DDL and DML statements?
- DDL (Data Definition Language): Defines and modifies database structure (CREATE, ALTER,
DROP).
- DML (Data Manipulation Language): Manipulates data in a database (INSERT, UPDATE,
DELETE).
SQL query to create a table 'students'
CREATE TABLE students (
student_id INT PRIMARY KEY,
name VARCHAR(100),
age INT
);
SQL query to insert values into 'students'
INSERT INTO students (student_id, name, age)
VALUES (1, 'John Doe', 20);
Display records of students with student_id = 30
SELECT * FROM students WHERE student_id = 30;
Difference between DELETE and DROP
- DELETE: Removes specific rows but retains the structure.
- DROP: Completely removes a table including its structure.
Explain Primary Key, Candidate Key, and Alternate Key
- Primary Key: Unique identifier for a record.
- Candidate Key: A column/set of columns that uniquely identify a record.
- Alternate Key: A candidate key not chosen as the primary key.
SQL query to display students born between 1990 and 2010
SELECT * FROM students WHERE birth_year BETWEEN 1990 AND 2010;
Display records of students with marks > 50
SELECT * FROM students WHERE marks > 50;