Basic SQL Flashcards
(196 cards)
What is Data-definition language (DDL)?
Provides commands for defining relation schemas, deleting relations, and modifying relation schemas
DDL is essential for setting up the structure of a database.
What does Data-manipulation language (DML) do?
Provides the ability to query information from the database and to insert, delete, and modify tuples in the database.
DML is crucial for interacting with the data stored in a database.
What is the purpose of integrity constraints?
Specifies integrity constraints that the data stored in the database must satisfy.
Updates that violate integrity constraints are disallowed.
What is a view definition in SQL?
Includes commands for defining views.
Views are virtual tables created based on the result-set of a query.
What does transaction control in SQL entail?
Includes commands for specifying the beginning and ending of transactions.
Transaction control is essential for maintaining data integrity during operations.
What is embedded SQL?
Defines how SQL statements can be embedded within general-purpose programming languages.
This allows for dynamic interaction with databases from within applications.
What does authorization in SQL address?
Includes commands for specifying access rights to relations and views.
This ensures that only authorized users can access or manipulate specific data.
Define char(n) in SQL.
A fixed-length character string with user-specified length n.
The full form, character, can be used instead.
What is varchar(n) in SQL?
A variable-length character string with user-specified maximum length n.
The full form, character varying, is equivalent.
What does int represent in SQL?
An integer.
The full form, integer, is equivalent.
What is the purpose of the numeric(p, d) type in SQL?
A fixed-point number with user-specified precision, consisting of p digits, with d of them to the right of the decimal point.
This allows for precise numerical calculations.
What does float(n) represent in SQL?
A floating-point number with precision of at least n digits.
This type is used for approximating real numbers.
What is the SQL command to create a table?
create table R(A1 D1, A2 D2, …, An Dn, <integrity>, <integrity>);</integrity></integrity>
This command establishes a new table structure in the database.
What does a primary key in a table ensure?
Uniqueness of each record in the table.
A primary key cannot contain NULL values.
What is a foreign key in SQL?
A field (or collection of fields) in one table that refers to the primary key in another table.
This establishes a relationship between the two tables.
How do you insert a new tuple into a table?
insert into table_name values (value1, value2, …);
This command adds a new record to the specified table.
What SQL command is used to delete all contents of a table?
delete from table_name;
This command removes all records but retains the table structure.
What does the update command do in SQL?
Modifies existing records in a table based on specified criteria.
Example: update table_name set column1 = value1 where condition;
What is the function of the ALTER TABLE command?
Used to add or drop an attribute to/from a table.
This command allows for modifying the structure of an existing table.
What is a typical structure of an SQL query?
select A1, A2, … An from r1, r2, … rm where P;
This structure is fundamental for querying data from one or more tables.
What is a check constraint in SQL?
A rule that limits the values that can be placed in a column.
Example: check (credits > 0); ensures that credits must be greater than 0.
What is the typical form of an SQL query?
The result of an SQL query is a relation
select A1, A2, … An
from r1, r2, … rm
where P
What does the SELECT clause do in SQL?
Lists the attributes desired in the result of a query