Relational databases and structured query language (SQL)

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/89

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

90 Terms

1
New cards

What is a database?

Structured collection of data stored for easy access and management

2
New cards

What is a relational database?

Database storing data in related tables, using keys to link them

3
New cards

What are the advantages of relational databases?

Reduce data redundancy and inconsistency, improve data integrity

4
New cards

Define 'table' in databases.

Structure storing data in rows (records), columns (fields)

5
New cards

What is a record?

A complete set of related data in a table (single row)

6
New cards

What is a field?

Column in a table, holds single type of data (e.g., age, name)

7
New cards

What is a primary key?

Unique identifier for each record in a table

8
New cards

What is a foreign key?

A field linking one table to the primary key in another table

9
New cards

What is data redundancy?

Unnecessary repetition of data in a database

10
New cards

What is data inconsistency?

Content conflicts/contradictions due to repeated or mismatched data

11
New cards

How does a relational database help eliminate redundancy?

Stores each unique item only once, linked by keys

12
New cards

How does a relational database help eliminate inconsistency?

Data changes update once, reflected everywhere it’s referenced

13
New cards

What is an entity in database design?

Object or thing about which data is stored (e.g., Student)

14
New cards

What is an attribute?

Property or detail describing an entity (e.g., Student Name, Age)

15
New cards

What is an entity identifier?

Unique value for each entity (usually the primary key)

16
New cards

What is SQL?

Structured Query Language—for managing and querying relational databases

17
New cards

What is a query in SQL?

Command to get, set, or change information in the database

18
New cards

Write an SQL SELECT statement to retrieve all columns.

SELECT * FROM table_name;

19
New cards

How do you select specific columns in SQL?

SELECT column1, column2 FROM table_name;

20
New cards

How do you filter records in SQL?

Use WHERE: SELECT * FROM table_name WHERE condition;

21
New cards

Write an SQL statement to find students aged 16.

SELECT * FROM Students WHERE Age = 16;

22
New cards

How do you sort results in SQL?

Use ORDER BY: SELECT * FROM table_name ORDER BY column1 ASC/DESC;

23
New cards

What does ASC mean in ORDER BY?

Sort ascending (lowest to highest)

24
New cards

What does DESC mean in ORDER BY?

Sort descending (highest to lowest)

25
New cards

How do you retrieve data from two tables in SQL?

Use JOIN: SELECT … FROM table1 JOIN table2 ON table1.key = table2.key;

26
New cards

How do you insert data into a table in SQL?

INSERT INTO table_name (col1, col2) VALUES (val1, val2);

27
New cards

How do you update data in SQL?

UPDATE table_name SET column1 = newvalue WHERE condition;

28
New cards

How do you delete data in SQL?

DELETE FROM table_name WHERE condition;

29
New cards

What is a JOIN in SQL?

Combines rows from two tables using a related column

30
New cards

What is an INNER JOIN?

Returns records where there is a match in both tables

31
New cards

What is a one-to-many relationship in databases?

One record in a table linked to multiple in another

32
New cards

What is a many-to-many relationship?

Records in both tables are linked to multiple in the other, often via link table

33
New cards

What is normalization?

Structuring a database to reduce redundancy and improve data integrity

34
New cards

What does 'referential integrity' mean?

Making sure relationships between tables are consistent (foreign key rules)

35
New cards

Explain how to set a primary key in SQL.

PRIMARY KEY column when creating table

36
New cards

Describe SQL command to create a table.

CREATE TABLE table_name (column1 datatype PRIMARY KEY, column2 datatype, …)

37
New cards

What is a wildcard in SQL?

% used to match any sequence of characters in LIKE queries

38
New cards

Write an SQL statement using LIKE.

SELECT * FROM Names WHERE Name LIKE 'A%';

39
New cards

How do you count records in SQL?

SELECT COUNT(*) FROM table_name;

40
New cards

How do you find the highest value in a column?

SELECT MAX(column) FROM table_name;

41
New cards

How do you find the lowest value in a column?

SELECT MIN(column) FROM table_name;

42
New cards

How do you find the average value in SQL?

SELECT AVG(column) FROM table_name;

43
New cards

How do you group records in SQL?

Use GROUP BY: SELECT column, COUNT(*) FROM table_name GROUP BY column;

44
New cards

How do you prevent SQL injection attacks?

Use parameterized queries, validate user input

45
New cards

What does SQL injection mean?

Manipulating SQL command using unsanitized user input

46
New cards

How is a foreign key set up in SQL?

FOREIGN KEY references primary key in another table

47
New cards

Explain the difference between SELECT and UPDATE.

SELECT gets data; UPDATE changes data

48
New cards

How are relationships shown in a database diagram?

Lines linking keys between tables

49
New cards

Why might you use two tables in a query?

Get richer data by combining related information

50
New cards

What is a transaction in databases?

A sequence of database operations that are treated as a single unit

51
New cards

Why use transactions?

Ensure data integrity, reliability

52
New cards

What is data integrity?

Accuracy and consistency of data over its lifecycle

53
New cards

What is meant by 'schema'?

Structure/definition of database tables and relationships

54
New cards

How do you search for all users with surname 'Smith'?

SELECT * FROM Users WHERE Surname = 'Smith';

55
New cards

How do you insert a new record into Students table?

INSERT INTO Students (Name, Age) VALUES ('Sam', 16);

56
New cards

How do you delete all students aged 20?

DELETE FROM Students WHERE Age = 20;

57
New cards

Write SQL to update surname for student with id 5.

UPDATE Students SET Surname = 'Jones' WHERE StudentID = 5;

58
New cards

What is an index in a database?

Structure that speeds up searching and sorting

59
New cards

How do you create a unique constraint?

UNIQUE(column) when creating table

60
New cards

What is a composite key?

Primary key made from more than one column

61
New cards

How do you limit results in SQL?

Use LIMIT: SELECT * FROM table_name LIMIT 10;

62
New cards

How to select distinct values in SQL?

SELECT DISTINCT column FROM table;

63
New cards

What is the advantage of using SQL for databases?

Fast, standardized, powerful for complex queries

64
New cards

What does SELECT * mean?

Select all columns in the table

65
New cards

How do you join Students and Courses tables?

SELECT … FROM Students JOIN Courses ON Students.CourseID = Courses.CourseID;

66
New cards

How are attributes and fields related?

Field is a column in a table, attribute describes entity

67
New cards

Why do databases use primary keys?

Guarantee each record is unique

68
New cards

What is a backup in databases?

Copy of data for safety in case of loss/failure

69
New cards

Give a reason for using relational database in business.

Data integrity, reduce repetition, combine info easily

70
New cards

What is an example of a relational database system?

MySQL, PostgreSQL, MS Access, Oracle

71
New cards

How is data stored physically in databases?

On disk in files; managed by DBMS (database management system)

72
New cards

What is the purpose of a DBMS?

Software to create, manage and control access to databases

73
New cards

How do you remove all records from a table?

DELETE FROM table_name;

74
New cards

What is meant by "cascade delete"?

Deleting record automatically deletes related records in other tables

75
New cards

When is a one-to-one relationship used?

When each record in a table links to one record in another table (rare)

76
New cards

Why is referential integrity important?

Prevents orphaned records, maintains link correctness

77
New cards

How do you write an SQL query to find all books published after 2015?

SELECT * FROM Books WHERE Year > 2015;

78
New cards

When should you use an index?

To speed up searching large datasets

79
New cards

What does 'NULL' represent in SQL?

No value or unknown data in a field

80
New cards

How do you select records where City is not NULL?

SELECT * FROM table WHERE City IS NOT NULL;

81
New cards

Write an SQL query to find all employees with salary over 30,000.

SELECT * FROM Employees WHERE Salary > 30000;

82
New cards

How do you use the BETWEEN operator?

SELECT * FROM Marks WHERE Score BETWEEN 70 AND 90;

83
New cards

What is cascading update?

Changes to primary key automatically update foreign key links

84
New cards

How do queries extract just two fields, Name and DateOfBirth?

SELECT Name, DateOfBirth FROM table_name;

85
New cards

How do you combine criteria in SQL queries?

Use AND or OR operators

86
New cards

Write a query for students aged 16 in London.

SELECT * FROM Students WHERE Age = 16 AND City = 'London';

87
New cards

How do you use aliases in SQL?

SELECT Name AS StudentName FROM Students;

88
New cards

What does JOIN ON mean in SQL?

Specifies column to link tables when joining

89
New cards

How to search for users whose name starts with S?

SELECT * FROM Users WHERE Name LIKE 'S%';

90
New cards