8.3 Databases.ddl&dml Flashcards

1
Q

What is Data Definition Language (DDL) used for in a DBMS?

A

DDL is used to create, modify, and remove the data structures that form a relational database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Data Manipulation Language (DML) used for in a DBMS?

A

DML is used to add, modify, delete, and retrieve the data stored in a relational database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an SQL script?

A

An SQL script is a list of SQL commands that perform a given task, often stored in a file for reuse.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do DDL and DML differ in function?

A

DDL works on the structure of the relational database, while DML works with the data stored in the database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What language is commonly used for both DDL and DML in most DBMSs?

A

Structured Query Language (SQL), which has been the industry standard since the 1970s.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the purpose of the SQL command CREATE DATABASE?

A

It creates a new database

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the SQL command CREATE TABLE do?

A

It creates a new table definition within a database

CREATE TABLE Student(
    StudentID CHARACTER,
    FirstName CHARACTER,
    SecondName CHARACTER,
    DateOfBirth DATE,
    ClassID CHARACTER);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the function of the SQL command ALTER TABLE?

A

It changes the definition of an existing table

ALTER TABLE Student ADD PRIMARY KEY (StudentID)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you add a primary key to a table in SQL?

A

By using the PRIMARY KEY constraint within the CREATE TABLE or ALTER TABLE statement.

ALTER TABLE Student ADD PRIMARY KEY (StudentID)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you define a foreign key in SQL?

A

Using FOREIGN KEY (…) REFERENCES … to establish a relationship with a primary key in another table.

ALTER TABLE Student ADD FOREIGN KEY ClassID REFERENCES Class(ClassID)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the SQL data type CHARACTER represent?

A

A fixed-length text field

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does VARCHAR(n) represent in SQL?

A

A variable-length text field with a maximum of n characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How is the BOOLEAN data type represented in SQL?

A

As TRUE or FALSE, but typically stored using the integers 1 (TRUE) and 0 (FALSE).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What kind of values does the INTEGER data type store in SQL?

A

integers dumbass

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the REAL data type used for in SQL?

A

Numbers with decimal places

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the typical format of the DATE data type in SQL?

A

YYYY-MM-DD

17
Q

What is the typical format of the TIME data type in SQL?

18
Q

What is the function of the SQL command SELECT FROM?

A

It fetches data from a database and all queries begin with SELECT

19
Q

How is the WHERE clause used in an SQL query?

A

It includes only rows in a query that match a given condition.

20
Q

What does the ORDER BY clause do in SQL?

A

It sorts the results of a query by a given column, either alphabetically or numerically.

21
Q

What is the purpose of the GROUP BY clause in SQL?

A

It arranges data into groups based on one or more columns

22
Q

How does INNER JOIN work in SQL?

A

It combines rows from different tables where the join condition is true.

SELECT Teacher.TeacherName AND Subject.SubjectName
FROM Teacher INNER JOIN Subject ON Teacher.LicenceNumber = Subject.LicenceNumber
23
Q

What does the SQL function SUM do?

A

It returns the sum of all the values in a specified column.

SELECT SUM (ExamMark)
FROM STUDENTSUBJECT
24
Q

What does COUNT do in an SQL query?

A

It counts the number of rows where the column is not NULL

25
What is the function of AVG in SQL?
It returns the average value for a column with a numeric data type
26
What does the SQL command INSERT INTO do?
It adds new row(s) to a table ``` INSERT INTO Student VALUES(S1301, Peter, Probert, 06/06/2011, 7A) ```
27
What is the function of DELETE FROM in SQL?
It removes row(s) from a table ``` DELETE FROM Student WHERE StudentID = ‘S1301' ```
28
How is the UPDATE command used in SQL?
It edits existing row(s) in a table