SQL Flashcards
What is a Database?
A SQL database is a collection of tables that stores a specific set of structured data.
What is a relational Database?
A relational database organizes data into tables which can be linked—orrelated—based on data common to each. This capability enables you to retrieve an entirely new table from data in one or more tables with a single query.
What is a database “Table”?
A table is a collection of related data held in a table format within a database. It consists of columns and rows.
What is a Primary Key and how many can one table have?
Primary key is a column or set of columns that uniquely identity a row in a table. A table can have one primary key. A primary key constraint can be on multiple columns though.
What is a Foreign Key and how many can one table have?
A Foreign Key is a field(columns) (or collection of fields(columns)) in one table that refers to the primary key in another table. The table with the foreign key is called the child table, and the table with the primary key is called the referenced or parent table.
A table can have as many foreign keys as you want up to 253.
What is a SQL Injection Attack and how do you protect yourself against these?
SQL injection attacks are when someone finds and exploits unsanitized inputs. They use the warning window provided to see if they can get information, sometimes companies pass too much information. Three ways to protect from injection attacks: Web Application Firewalls - analyze and separate malicious HTTP and HTTPS request heading to your website. Parameterized Queries - Parameterized queries will segregate the data added by an user from the code that runs the application so the two don’t interact with each other. Reduce account privileges so that unauthorized accounts can’t get admin privileges.
What is a Sql Server stored procedure?
A SQL stored procedure (SP) is a collection SQL statements and sql command logic, which is compiled and stored on the database. Stored procedures in SQL allows us to create queries to be stored and executed on the server. Stored procs can also be cached and reused.
What language is used to write Stored procedures?
Transact SQL or T/SQL for short
What language do you use to communicate with the database?
Structured Query Language - SQL
What are the different types of statements available to you in TSQL?
Data Definition Language - Create, Alter, Drop, Truncate etc…
Data Manipulation Language - Insert, Delete, Bulk Insert, Select, Update, merge etc….
What are indexes?
Sql index is a quick lookup table for finding records users need to search frequently. When you create a primary key a clustered index is automatically created with it. Same as when you put a unique constraint on a column.
If you wanted to delete information from a table what statement would you use?
SQL delete statement. DELETE FROM table name Where Id = @Id
What is the truncate statement used for? What is the key difference between this and your other options to remove data?
A truncate statement is DDL (Data Description Language) statement that marks extents of a table for deallocation. Meaning it removes the data from the table. The key difference is that it won’t delete the schema of the table and there is no where clause to target specific rows. It won’t log the deleted data so it is faster and an increase in performance.
What are the basic parts of a simple TSQL Query
Input/Select, Execution, Output
When are “Joins” used?
Joins are used to return data that is related in a relational database. Data can be related in 3 ways: one to one (student only as one id), one to many(a customer can have many orders), and many to many (dr can have many patients and patients can have many dr.)