DAF Flashcards
Database Administration Fundamentals
database (db)
- a structure or organized collection of data, categories of information and the relationship between these categories, typically stored in electronic format.
- Allows you to input, organize, and retrieve data quickly.
- minimize mistakes and redundancy
query
an inquiry into the database that returns information back from the database
database servers
contain databases so they can be accessed by multiple users and provide a high level of performance
DBMS - database management system
a collection of programs that indirectly enables you to enter, organize, and select data in a database
3 types of databases
- Flat-type databases
- Hierarchical databases
- Relational databases
Flat-type databases
- simplistic in design (two-dimensional tables - rows & columns)
- most commonly used in plain-text formats
- purpose is to hold one record per line
- they make access, performance, and queries very quick
field refers to…
a column in a table taht is designed to maintain specific informatio;n about every record in the table
-vertical entry
a record refers to…
a row
- each individual entry that exists in a table
- horizontal entity
hierarchical database
- similar to a tree structure
- each “parent” table can have multiple “children”
- each child can have only one parent
relational database
- most important
- data is stored in tables
- new information is automatically added into the table without the need to reorganize the table itself
- can gave multiple parents
Database objects are inherently divided into two broad categories…
storage and programmability
Definition of constraints
limitations or rules placed on a field or column to ensure that data that is considered invalid is not entereed
types of constraints
- unique
- check
- default
- not null
- primary key
- foreign key
unique constraint
allows the database administer to specifically identify which column should not contain duplicate values
check constraint
allows the administrator to limit the types of data a usere can insert into the database
default constraint
is used to insert a default value into a column if no other value is specified
not null constraint
ensures that data is entered into a cell - cell cannot be blank
primary key constraint
- defines each record -uniquely identifies each record in a database table
- cannot be duplicated
- must contain unique values and cannot contain NULL values
- all attributes are functionally dependent of
- each table has a primary key, and only one primary key
foreign key constraint
-points to a primary key in another table
DML stands for
Data Manipulation Language
Data Manipulation Language
is the language element that allows you to use the core statements INSERT, UPDATE, DELETE, MERGE, SELECT
SELECT statement
- selects data from a database
- retrieves rows from the database and enables the selection of one or many rows or columns from on or many tables
INSERT statement
adds one or more new rows to a table or a view
UPDATE statement
- updates data
- changes existing data in one or more columns in table or view
DELETE statement
Removes rows from a table or view
MERGE statement
Performs insert, update, or delete operations on a target table based on the results of a join with a source table
DDL means
Data Definition Language
data definition language definition
deals with creating database objects like tables, constraints, and store procedures
core DML statements
- SELECT
- INSERT
- UPDATE
- DELETE
- MERGE
core DDL statements
- USE
- CREATE
- ALTER
- DROP
- TRUNCATE
- DELETE
USE statement
changes the database context
CREATE statement
creates a SQL Server database object (database, index, view, table, or procedure)
database object
- database
- index
- view
- table
- procedure
ALTER statement
- changes an existing object
- adds, deletes, or modifies columns in a table
- or changes the data type in a table
DROP statement
- Removes an object from the database
- deletes column, constraint, database, index, table, view
TRUNCATE statement
- removes data from inside a table, leaves the table
- frees the space used by those rows
DELETE statement
- remove rows from a table
- does not free up the space used
when to use TRUNCATE
if you are deleting data from tables in a large database
when to use DELETE
if you are deleting data from smaller databases
three types of files used to store databases
- primary data files
- secondary data files
- transaction log file
primary data files
- .mdf extension
- first files created in a dabase
- contain user-defined objects (tables, views) and system tables
secondary data files
- .ndf extenstion
- on separate physical hard disks to give a database more room
transaction log file
- .ldf extension
- don’t contain any objects such as tables or views
database index
data structure that improves the speed retrieval operations on a database table
tables
- two-dimensional objects consisting of rows and columns
- used to store data
SSMS (SQL Server Management Studio)
primary tool to manage a server and its databases using a graphical interface
data type
an attribute tha specifies the tpe of data an object can hold, as well as how many bytes each data type takes up
if two data types differ only in how many bytes each uses…
the more bytes usually has a larger range of values and/or increased precision
predefined data types
built in data types
Exact numeric data types
- most common SQL Server data types used to store numeric information
- whole numbers only
int (integer numeric data type)
- primary integer data type (whole number)
- used to store mathematical computations
- used when no decimal point is required
precision (p)
max total number of decimal digits that can be stored in a numeric data type (both to left and right of decimal point)
-value must be at least 1 and at most 38 (default is 18)
money and small money
data types used to represent monetary or currency values
approximate numeric data types
not as commonly used
date and time data types
deal with dates and times
built-in data types are organized into what general categories
- exact numbers
- approximate numbers
- date and time
- character strings
- unicode character strings
- binary strings
- other data types
- CLR data types
- spatial date types
money data type
used in places where you want money or currency involved in your database - doesn’t calculate percentages
datetime data type
store date and time data in different formats
Varchar data type
-character string data type supporting English attributes
Boolean data type
bit data type
Float data type and Real data type
- used in conjunction with floating-point numeric data type
- considered approximate-number data type
exact numeric data types examples
- int
- bigint
- bit
- decimal
- numeric
- money
- small money
approximate numeric data types
- more precision
- includes decimals
implicit conversion
when a conversion (converting values from one data type to another) is done automatically
cast and convert
used to force conversion
explicit conversion
when a conversion is forced using callout function
regular character string
- uses one byte of storage for each character
- allows you to define one of 256 possible characters
- accommodates English and European languages
unicode character string
- uses two bytes of storage per character
- represent one of 65,536 characters
- accommodates most languages
view
- a virtual table consisting of different columns from one or more tables
- stored in a database as query objects
- security mechanism
stored procedure
- previously written SQL statement that has been “stored” or saved into a database
- used to save time
SQL injection
an attack in which malicious code is inserted into strings to be passed on later when parsing or executing statements
primary form of SQL injection
direct insertion or code into user-input variables that are concatenated with SQL commands and then executed
VAR element
-preserve space in the row in which this element resides on the basis of the columns defined size and not the actual number of characters in the string
nchar and nvarchar
are unicode characters strings can be fixed or variable
purpose of a table
provide a structure for storing data within a relational database
purpose of a table
provide a structure for storing data within a relational database
The SQL command for retrieving any data from a database the data
SELECT
what three things do you need to identify in your statement in order to form a proper SELECT query
- what columns to retrieve
- what tables to retrieve them from
- what conditions, if any, must satisfy
BETWEEN clause
- allows you to specify the range to be used in a “between x and y” query format
- select values within a given range
NOT keyword
is used to search data in terms of what you don’t want in your output
UNION clause
allows you to combine the results of any two or more queries into a resulting single set that will include all the rows belonging to the query in that union
EXCEPT clause
returns any distinct values from the left query that are not also found on the right query
INTERSECT clause
returns any distinct values not found on both the left and right sides of this operand
JOIN clause
allows you to combine related data from multiple table sources
to insert data…
- you can use SSMS
- or the INSERT statement
UPDATE statement
- changes data in a table or a view
- updates existing rows in a table