Basic Flashcards
What is SQL?
Structured Query Language - programming language for managing data. Performs tasks such as retrieval, updation, insertion and deletion of data from a database.
What is DBMS?
Data Base Management System - allows for the creation, maintenance, and use of a database. “File Manager “ that manages data
What is RDBMS? What is NRDBMS?
Relational Data Base Management System - stores data in tables and can manipulate it. Examples : MySQL, SQL Server, Oracle
Non-relational database management system a database that does not use the tabular schema of rows and columns found in most traditional database systems; uses a storage model that is optimized for the specific requirements of the type of data being stored
What is a database?
An organized collection and storage of data
What are tables? What are fields?
Tables = data organized in columns and rows and the ROWS ( records), COLUMNS (fields)
What is a primary key?
A unique identifier for each record. Ex: VIN, DL #, Phone # - NO DUPLICATE , NO NULL accepted
What is a unique key?
A unique constraint that is a group of one or more than one fields or columns that identify a database or record
What is a null value?
A data value that does not exist in database
What is a foreign key?
A column or group of columns in a table that provides link between data in 2 tables - related to primary key of another table
What is a join?
A clause/ keyword used to combine rows in 2 or more tables
What are the types of join? Explain each
a. Inner Join =return matching rows in both tables
b. Right join =return all rows in right table - even if no matches in left table
c. Left join = return all rows in left table - even if no matches in right table
d. Full join = return rows when one table has match
e. Self join = joins table to itself
f. Cartesian join (Cross join) = returns products of sets of records of 2 or more joined tables
What is normalization? What are the advanatages?
Database technique of reducing the data redundancy and dependency by organizing fields and tables in database - add, delete, modify fields that can be in 1 single table
Better Database organization More Tables with smaller rows Efficient data access Greater Flexibility for Queries Quickly find the information Easier to implement Security Allows easy modification Reduction of redundant and duplicate data More Compact Database Ensure Consistent data after modification
What is denormalization?
Database technique of adding the data redundant data and dependency in database
What are all the different normalizations?
a. First normal form (1NF) = cant have multiple values - should be atomic (cant be divided) values
b. Second normal form (2NF) =1NF + dependencies removed and placed in seperate table
c. Third normal form (3NF) = 2NF + should have no Transitive dependency ( an indirect relationship between values in same table)
d. “Boyce Codd Normal Form” =
e. Fourth normal form ( 4NF) = 3NF + should not have 2 or more independent Multivalued dependency (when 2 or more attributes in table are independent of each other but depend on 3rd attribute )
f. Fifth normal form ( 5NF) = 4NF + cant be broken down into smaller tables without data loss
g. Sixth normal form (6NF) = has not been determined yet!
What is a view? What are views used for?
A virtual table with rows and columns used for data security ( the enclose table name) and analysis
- Restricting access to data.
- Making complex queries simple.
- Ensuring data independence.
- Providing different views of same data.
What is an index?
Tuning method to allow faster retrieval of records from table
What are the types of indexes?
a. Unique = Index key column doesn’t have duplicate values if column is unique
b. Clustered = Reorders the physical order of the table and search based on the key values; for “easy retrieval of data”; sorts out rows by column
c. Non-clustered = Does not alter the physical order of the table and maintains logical order of data; stored at one place and table data is stored in another place
What is a cursor?
A control/ pointer that allows you to travel over rows and columns
What is a relationship? What are the types?
What is an entity?
Established relationships between 2 or more tables - involves common fields in 2 or more tables
a. One - One (1:1) = 1 record in table associated with ONLY one record in another table
b. One - Many (1:N) = 1 record in table associated with one or more records in another table
c. Many - Many (M:N) = many records in table associated with many records in another table
A person, place, or thing in the real world about which data can be stored in a database
What is a query?
A code written in order to get the information back from the database
What is a subquery? What are the types of subquery?
A query inside another query - outer query (main query ) + inner query (sub-query) ; subquery first and then result passed to main query
a. Correlated =inner query dependent on values of outer query for its values
b. Non- correlated =inner query isnt dependent on values of outer query for its values; stands alone
What is a stored procedure?
A function that consists of many SQL statements to access the database system.
What is a trigger? What are nested triggers?
A code or programs that automatically execute with response to event on a table or view in a database
Execute after a DML or DDL operation is performed
What is difference between TRUNCATE, DROP, and DELETE?
Truncate = delete data rows in tables but not table itself ; cant be rolled back
Delete = removes specific records from table
Drop = removes table from database, cant be rolled back
What are local and global variables and there differences?
Variables are the object which acts as a placeholder to a memory location
Local variables = variables which can be used or exist inside the function; not known and cant be used; can be created when function is called
Global variables =variables which can be used or exist throughout the program; cant be created when function is called
What is a constraint? What are the various levels?
Used to specify rules for data in a table by limiting the type of data that can go in data. Examples:
a. NOT NULL = enforces a column to NOT accept NULL values
b. CHECK = enables a condition to check the value being entered into a record
c. DEFAULT = provides a default value to a column when the INSERT INTO statement does not provide a specific value
d. UNIQUE
e. PRIMARY KEY
f. FOREIGN KEY
- column level constraint (Column-level constraints (except for check constraints) refer to only one column)
- table level constraint (Table constraints allow you to specify more than one column in a PRIMARY KEY, UNIQUE, CHECK, or FOREIGN KEY constraint definition)
What is data integrity?
The accuracy and consistency of data stored in a database; Can define integrity constraints (are a set of rules used to maintain the quality of information)
What is auto increment?
Allows the user to create a unique number to be generated when a new record is inserted into the table; mainly used when primary key is introduced
What is a data warehouse?
A central repository of data from multiple sources of information; data are consolidated, transformed and made available for the mining and online processing
What is user defined functions? What are the different types?
Functions written by us the user of a program or environment for our own requirement ; can be called or executed when needed
a. Scalar function = accept one or more parameters but return only a single value result (mandatory) from an input value
b. Incline table valued function = similar to a “view” returns virtual table since it returns a table data type as a result; accepts parameters
c. Multi-statement table valued function = returns a table as output and this output table structure can be defined by the user
What is collation? What are the types of collation sensitivity?
Set of rules that determine how character data can be sorted, matched, arranged, and compared
a. Case Sensitivity – A and a and B and b. ( SQL is case insensitive)
b. Accent Sensitivity – (considers the accented and unaccented versions of letters to be identical for sorting purposes)
c. Kana Sensitivity – Japanese Kana characters. (Specifies that SQL Server distinguish between the two types of Japanese kana characters: Hiragana and Katakana. If not selected, SQL Server considers Hiragana and Katakana characters to be equal)
d. Width Sensitivity – Single byte character and double byte character ( distinguishes between a single-byte character and a double-byte character. If “WS” is not set/selected, SQL Server treats the single-byte and double-byte characters as the same for sorting purposes)
What are stored procedures? Advantages and Disadvantages of stored procedures?
What is a recursive stored procedure?
A prepared SQL code that you can save, so the code can be reused over and over again
Good = modular programming – means create once, store and call for several times whenever required
- fast execution
- reduce network traffic
- data security
Bad = can be executed only in the Database and utilizes more memory in the database server.
- hard to debug
- need expert developer - hard to code
- expensive
- hard to port (move) to upgraded versions
A procedure that references itself - “calls on itself”
What is online transaction processing?
A category of data processing focused on transaction-oriented tasks; Involves inserting, updating, and/or deleting small amounts of data in a database; mainly deals with large numbers of transactions by a large number of users IN REAL TIME.
What is a clause?
In-built functions available to us so we can deal with data easily stored in the table; help us filter and analyze data quickly; when we have large amounts of data stored in the database, we use Clauses to query and get data required by the user.
What are the most common important SQL commands?
SELECT - extracts data from a database UPDATE - updates data in a database DELETE - deletes data from a database INSERT INTO - inserts new data into a database CREATE DATABASE - creates a new database ALTER DATABASE - modifies a database CREATE TABLE - creates a new table ALTER TABLE - modifies a table DROP TABLE - deletes a table CREATE INDEX - creates an index (search key) DROP INDEX - deletes an index
What is a command? What is union, minus, alias, and interact commands?
Instructions used to communicate with a database to perform tasks, functions, and queries with data; can be used to search the database and to do other functions like creating tables, adding data to tables, modifying data, and dropping tables.
UNION = operator to combine the results of two tables, and it eliminates duplicate rows from the tables.
MINUS = operator to return rows from the first query but not from the second query. Matching records of first and second query and other rows from the first query will be displayed as a result set.
INTERSECT= operator to return rows returned by both the queries.
ALIAS name can be given to a table or column. This alias name can be referred in WHERE clause to identify the table or column.