SQL Flashcards
SQL
Structured Query Language
What can you use SQL for?
Create, read/retrieve, update and delete any data in a database. The data can be a single value, a row, a column, a table or even an entire database.
How do you define text or character based value in SQL
You can define a text- or character-based value in SQL by placing the value inside single quotes (‘ ‘)
How do you punctuate a SQL statement?
with a semi colon (;)
What is a database?
Databases are collections of data that are organized for easy management, storage, update, search and retrieval. Databases can consist of items in any format such as audio, video, microfiche, print and electronic files.
What is DBMS?
Database management systems are computer software that enables a user to create and manage a database using a certain platform.
What is RDBMS?
Think of relational databases as systems of ordinary row-and-column tables that are interrelated.
How to populate a table?
use INSERT INTO
What is normalization (in the case of databases)?
The term “normalization” refers to the process of analyzing the data that your system is required to store, and organizing it so that every fact is stored in exactly one place. Understanding how to normalize data is an absolute requirement for the database programmer who wants to design databases.
Why would you denormalize?
denormalization, the deliberate re-intoduction of redundant values to improve the usability of the database.
typically done for performance reasons, to reduce the number of table joins. This is not a good idea in a transactional environment as there are inherent data integrity risks or performance risks due to excessive locking to maintain data integrity.
What are DML triggers and what types of triggers can you have on a SQL Server table?
A trigger, as the name implies, is a collection of SQL statements triggered to execute by an insert, update, or delete action on a table that affects its contents. INSTEAD OF and AFTER can be specified for each trigger. When INSTEAD OF is specified, the trigger takes the place of the triggering action. So if you had an INSTEAD OF UPDATE trigger, the code inside the trigger would be executed instead of the original update. AFTER triggers are the same as the FOR used in earlier versions of SQL Server. This just means the trigger will execute following the original action. An AFTER UPDATE trigger will allow the update to complete and then the update trigger will execute. For more information, see DML Trigger Planning Guidelines.
What is the difference between a clustered and a non-clustered index?
his is one of my favorite questions for sorting out the developers that have an understanding beyond your basic T-SQL to more of an understanding of performance. I’m looking for them to tell me that a clustered index represents the physical order of the rows as they are stored in the database. A non-clustered index is a logical ordering of the rows.
Both types of indexes facilitate faster lookups and joins.
As a follow-up question, should they get this right, ask them to tell you how many clustered indexes you can have on a table. The answer should be one. Rows can only be physically stored with one ordering.
What is a Linked Server?
Another question that can tell you if the candidate has experience with distributed databases is “What is a Linked Server?” A linked server is a reference from one SQL Server server to another. If you have databases on another SQL Server server that contains data you need for your system, you could create a link server on your server to the other SQL Server server. Then, you can use the four-part name of the remote table to use it within your local queries.
How do you auto number rows in SQL Server?
ometimes I have to rephrase this one to get the answer. What I’m looking for here is the candidate’s knowledge of identity columns. Identity columns are used to automatically increment a column in a table from a seed (or starting) value and by a defined increment. If no seed is specified and no increment is specified, the first entry is 1 and the subsequent entries are incremented by 1. If either the seed or the increment is specified, other must be specified.
What is a left outer join? Give an example.
The answers I get on this one blow me away. I can’t believe how many candidates I’ve interviewed that do not grasp this concept. Assume you have two tables, TableA and TableB. You need all the rows from TableA and all matching rows from TableB. You would use a left outer join to accomplish this with TableA being the left table as in the following.
SELECT *
FROM TableA
LEFT OUTER JOIN TableB
ON TableA.Col1 = TableB.Col1