SQL Server

What is a relational database?

relational database (RDB) is a collective set of multiple data sets organized by tablesrecords and columns. RDBs establish a well-defined relationship between database tables. Tables communicate and share information, which facilitates data searchability, organization and reporting.

RDBs use Structured Query Language (SQL), which is a standard user application that provides an easy programming interface for database interaction.

Relational databases are based on the relational modelan intuitive, straightforward way of representing data in tables. In a relational database, each row in the table is a record with a unique ID called the key. The columns of the table hold attributes of the data, and each record usually has a value for each attribute, making it easy to establish the relationships among data points.

Benefits of Relational Databases:

  • Data Consistency
  • Commitment and Atomicity
  • Stored Procedures and Relational Databases
  • Database Locking and Concurrency

Relational Database Terms

Below are the unique terms and specific definitions that will help you understand what a RDB can do and how it works:

Row : A set of data constituting a single item.

For example, the data for a single employee (e.g. first name, last name, employee ID, hire date, work location, etc.) of a company would be displayed in a row. A row can also be called a record, an entity, or a tuple.

Column: Labels for elements of rows. A column gives context to the information contained in rows. For an employee database, the column headers could be the items listed above for employees. A column is also known as an attribute or a field.

Table: A group of rows that match the parameters set up for the table. The data in a table must all be related. An employee database may have separate tables for active employees, retired employees, and former employees. A table is also known as a relation or base revelar.

View: A set of data based on a query via the RDBMS; also known as result set or derived revelar.

Domain: The set of possible values for a given column. For example, the phone number and ZIP code columns would be numbers, while first and last names would be limited to letters.

Constraint: A narrowing of a domain. For example, the domain of the work location on a employee record would be alphanumeric, but it could be restricted to a predefined list rather than being a free-form field. The phone number field would be constrained to 10 digits.

Primary key: The unique identifier of a row in a table.

Foreign key: The unique identifier of a row in another table.

Distributed Database: A database that stores data in multiple locations, rather than on a single hard drive or server.


The power of a relational database is in the links and relations. By connecting rows in different tables through the use of primary and foreign keys, you can create views, reports, and other slices of information to serve your organization. There are three primary types of database relationships:

One-to-One: One row in one table is connected to one and only one row in another table. For example, a Social Security number is linked to a single employee.

One-to-Many: One row in one table is connected to zero, one, or more than one rows in another table. For example, one work location can be linked to many employees.

Many-to-Many: Zero, one, or many rows in one table are linked to zero, one, or many rows in another table. For example, multiple employees can be assigned to multiple projects.

What is a subquery in SQL?

SubQuery is a query within another query. The outer query is called as main query and inner query is called as SubQuery.

The SubQuery generally executes first, and its output is used to complete the query condition for the main or outer query. Subquery must be enclosed in parentheses.

Subqueries are on the right side of the comparison operator. You can place the Subquery in a number of SQL clausesWHERE clauseHAVING clauseFROM clause.

Subqueries can be used with SELECTUPDATEINSERTDELETE statements along with expression operator. It could be equality operator or comparison operator such as =, >, =, <= and Like operator.

ORDER BY command cannot be used in a SubQueryGROUPBY command can be used to perform same function as ORDER BY command.

A Sample Syntax Example for SubQuery:

SELECT column_name

FROM table_name

WHERE column_name expression operator


SQL Server Online Training

What is a NULL Value?

A field with a NULL value is a field with no value.

If a field in a table is optional, it is possible to insert a new record or update a record without adding a value to this field. Then, the field will be saved with a NULL value.

Note: It is very important to understand that a NULL value is different from a zero value or a field that contains spaces. A field with a NULL value is one that has been left blank during record creation!

DBCC Commands @ SQL Server

DBCC (Database consistency checker) act as Database console commands for SQL Server to check database consistency.

They are grouped as:




A brief description of the DBCC command categories is given below.

Maintenance: Maintenance tasks on a database, index, or filegroup.

Miscellaneous: Miscellaneous tasks such as enabling trace flags or removing a DLL from memory.

Informational: Tasks that gather and display various types of information.

Validation: Validation operations on a database, table, index, catalog, filegroup, or allocation of database pages.

Uses Of DBCC:

DBCC give details in form of statistics about the SQL Server. They can be used for Maintenance of database, index, or filegroup. DBCC Commands can be used to perform validation operations on a database, table, index, catalog, filegroup, or allocation of database pages.

They can perform miscellaneous tasks such as enabling trace flags or removing a DLL from memory. DBCC INDEXDEFRAG, DBCC ERRORLOG, DBCC CACHESTATS are one of the few DBCC commands

List of frequently used DBCC Command


Used to perform consistency check for a table/catalog for a particular database.


Used to check integrity of a particular constraint or all constraints on a particular table for a database.


Used to check page usage and allocation of a database.

  1. DBCC CHECKTABLE(tablename)

Used to verify data page integrity, page offsets, data page links, page pointers, index pointers, index sort order for a specified table.

  1. DBCC SQLPERF(logspace)

Displays T-log size and space used % for all databases.


Display Extent information for a database.

  1. DBCC CHECKIDENT(tablename)

Used to check identity information or to return current identity value for a particular table.


Used to disable tracing


Used to enable tracing.


Displays the trace status.


Displays the active SET options for a particular database

  1. DBCC INPUTBUFFER(sessionid)

Used to get the last statement sent by session to SQL server.

  1. DBCC SHRINKDATABASE(databasename)

Used to shrink data and log files for a particular database. It release the free space to OS.

  1. DBCC SHRINKFILE(file_id)

Used to shrink individual database files.


Displays virtual log file information contained in a T-log file.

  1. DBCC HELP(<dbcc command>)

Displays the syntax of a DBCC command. To know syntax of DBCC SQLPERF, execute


Displays SQL Server memory allocation status.

  1. DBCC Cleantable

Used to reclaim space from dropped variable length columns in tables/indexed views

  1. DBCC Opentran

Displays information about oldest active transaction and oldest distributed and non-distributed replication transaction

For more commands, please log on to: http://sqlschool.com/SQL-DBA-Course.html

or email to our trainer: saiphanindrait@yahoo.com
We offer free technical support for this type of informational queries.