SQL DBA Course

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.

TYPES OF DATABASE RELATIONSHIPS

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 SQL?

SQL stands for Structured Query Language. SQL is used to communicate with a database. According to ANSI (American National Standards Institute), it is the standard language for relational database management systems. It is used to perform operations on the data present in database.

SQL statements are used to perform tasks such as update data on a database, or retrieve data from a database.

Although most database systems use SQL, most of them also have their own additional proprietary extensions that are usually only used on their system.

However, the standard SQL commands such as “Select”, “Insert”, “Update”, “Delete”, “Create”, and “Drop” can be used to accomplish almost everything that one needs to do with a database.

SQL commands are divided into several different types, among them data manipulation language (DML) and data definition language (DDL) statements, transaction controls and security measures.

Some common relational database management systems that use SQL are: Oracle, Sybase, Microsoft SQL Server, Access, Ingres, etc.

MSSQL @@ROWCOUNT Tutorial

MSSQL @@ROWCOUNT Tutorial

The @@ROW COUNT variable returns the number of rows read by the last executed statement. If any statement does not return any rows, then value of @@ROWCOUNT variable is set to zero.

MSSQL @@ROWCOUNT VARIABLE SYNTAX

@@ROWCOUNT

Using @@ implies that it is a global variable. Also @@ROWCOUNT returns the value of int type i.e. the maximum no of rows @@ ROWCOUNT can return is 231 (2,147,483,647). For returning rows greater than this limit, ROWCOUNT_BIG function is used.

More Information visit: www.sqlschool.com

SQL GRANT REVOKE Commands

SQL GRANT REVOKE Commands

DCL commands are used to enforce database security in a multiple user database environment. Two types of DCL commands are GRANT and REVOKE. Only Database Administrator’s or owner’s of the database object can provide/remove privileges on a database object.

SQL GRANT Command

SQL GRANT is a command used to provide access or privileges on the database objects to the users.

The Syntax for the GRANT command is:

GRANT privilege_name
ON object_name
TO {user_name |PUBLIC |role_name}
[WITH GRANT OPTION];

  • privilege_name is the access right or privilege granted to the user. Some of the access rights are ALL, EXECUTE, and SELECT.
  • object_name is the name of an database object like TABLE, VIEW, STORED PROC and SEQUENCE.
  • user_name is the name of the user to whom an access right is being granted.
  • user_name is the name of the user to whom an access right is being granted.
  • PUBLIC is used to grant access rights to all users.
  • ROLES are a set of privileges grouped together.
  • WITH GRANT OPTION – allows a user to grant access rights to other users.

For Example:

GRANT SELECT ON employee TO user1;

This command grants a SELECT permission on employee table to user1.

You should use the WITH GRANT option carefully because for example if you GRANT SELECT privilege on employee table to user1 using the WITH GRANT option, then user1 can GRANT SELECT privilege on employee table to another user, such as user2 etc.

Later, if you REVOKE the SELECT privilege on employee from user1, still user2 will have SELECT privilege on employee table.

Create a Database by Script

SQL Server accepts Transact-SQL (which is an extended version of the SQL standard), so you could create the database by running the following SQL script.

USE master;
GO
CREATE DATABASE Music;
GO

To do this, open a new query by clicking New Query in the toolbar and run an SQL CREATE DATABASE statement.

Just as you can specify certain properties when creating a database via the GUI, you can include those same properties when creating a database by script. Here’s an example of specifying settings for the data and log files.

USE master ;
GO
CREATE DATABASE Music
ON
( NAME = Music_dat,
FILENAME = ‘C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\Music.mdf’,
SIZE = 10,
MAXSIZE = 50,
FILEGROWTH = 5 )
LOG ON
( NAME = Music_log,
FILENAME = ‘C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\Music_log.ldf’,
SIZE = 5MB,
MAXSIZE = 25MB,
FILEGROWTH = 5MB ) ;
GO

What are the typical uses of service accounts in running SQL Server components?

Service accounts are all about security and access. So, for example, SQL Agent runs as a service and it can be configured (should be) to run under a service account. Let’s assume that you use Agent to run backups. Let’s also assume you backup to a shared file location on your network that’s not local to the machine you’re running SQL Agent on. You’ll need to ensure that the account configured for SQL Agent has access to that shared file location. While this may seem like work, what it in fact is doing is following the method of least access. That service account has to have access to that share, but it doesn’t need access to other file locations on your system, so you only give it what it needs and nothing more. Same thing applies to the other services and service accounts.

For More Information www.sqlschool.com

MS SQL Server – Editions

SQL Server is available in various editions. This chapter lists the multiple editions with its features.

Enterprise − This is the top-end edition with a full feature set.

Standard − This has less features than Enterprise, when there is no requirement of advanced features.

Workgroup − This is suitable for remote offices of a larger company.

Web − This is designed for web applications.

Developer − This is similar to Enterprise, but licensed to only one user for development, testing and demo. It can be easily upgraded to Enterprise without reinstallation.

Express − This is free entry level database. It can utilize only 1 CPU and 1 GB memory, the maximum size of the database is 10 GB.

Compact − This is free embedded database for mobile application development. The maximum size of the database is 4 GB.

Datacenter − The major change in new SQL Server 2008 R2 is Datacenter Edition. The Datacenter edition has no memory limitation and offers support for more than 25 instances.

Business Intelligence − Business Intelligence Edition is a new introduction in SQL Server 2012. This edition includes all the features in the Standard edition and support for advanced BI features such as Power View and PowerPivot, but it lacks support for advanced availability features like AlwaysOn Availability Groups and other online operations.

Enterprise Evaluation − The SQL Server Evaluation Edition is a great way to get a fully functional and free instance of SQL Server for learning and developing solutions. This edition has a built-in expiry of 6 months from the time that you install it.

2005 2008 2008 R2 2012 2014
Enterprise Yes Yes Yes Yes
Standard Yes Yes Yes Yes
Developer Yes Yes Yes Yes
Workgroup Yes Yes No No
Win Compact Edition – Mobile Yes Yes Yes Yes
Enterprise Evaluation Yes Yes Yes Yes
Express Yes Yes Yes Yes
Web Yes Yes Yes
Datacenter No No
Business Intelligence Yes

Types of keys is SQL Server

What is Key? Keys are fields in a table which participate in below activities in RDBMS systems:

  • To create relationships between two tables.
  • To maintain uniqueness in a table.
  • To keep consistent and valid data in database.
  • Might help in fast data retrieval by facilitating indexes on column(s).

SQL Server supports various types of keys, which are listed below:

  1. Candidate Key
  2. Primary Key
  3. Unique Key
  4. Alternate Key
  5. Composite Key
  6. Super Key
  7. Foreign Key

Before discussing each type in brief, have a look on the below image used as an an example to define types of keys.

Lets discuss each type in detail:

  • Candidate Key: Candidate key is a key of a table which can be selected as a primary key of the table. A table can have multiple candidate keys, out of which one can be selected as a primary key.

Example: Employee_Id, License_Number and Passport_Number are candidate keys

  • Primary Key: Primary key is a candidate key of the table selected to identify each record uniquely in table. Primary key does not allow null value in the column and keeps unique values throughout the column. In above example, Employee_Id is a primary key of Employee table. In SQL Server, by default primary key creates a clustered index on a heap tables (a table which does not have a clustered index is known as a heap table). We can also define a nonclustered primary key on a table by defining the type of index explicitly.

A table can have only one primary key and primary key can be defined in SQL Server using below SQL statements: CRETE TABLE statement (at the time of table creation) – In this case, system defines the name of primary key ALTER TABLE statement (using a primary key constraint) – User defines the name of the primary key Example: Employee_Id is a primary key of Employee table.

  • Unique Key: Unique key is similar to primary key and does not allow duplicate values in the column. It has below differences in comparison of primary key:

It allows one null value in the column. By default, it creates a nonclustered index on heap tables. Alternate Key Alternate key is a candidate key, currently not selected as primary key of the table. Example: License_Number and Passport_Number are alternate keys.

  • Composite Key: Composite key (also known as compound key or concatenated key) is a group of two or more columns that identifies each row of a table uniquely. Individual column of composite key might not able to uniquely identify the record. It can be a primary key or candidate key also.

Example: In salary table, Employee_Id and Salary_Month_Year are combined together to identify each row uniquely in Salary table. Independently Employee_Id or Salary_Month_Year column cannot identify each row uniquely. We can create a composite primary key on Salary table using Employee_Id and Salary_Month_Year columns.

  • Super Key: Super key is a set of columns on which all columns of the table are functionally dependent. It is a set of columns that uniquely identifies each row in a table. Super key may hold some additional columns which are not strictly required to uniquely identify each row. Primary key and candidate keys are minimal super keys or you can say subset of super keys.

In above example, In Employee table, column Employee_Id is sufficient to uniquely identify any row of the table, so that any set of column from Employee table which contains Employee_Id is a super key for Employee Table. For example: {Employee_Id}, {Employee_Id, Employee_Name}, {Employee_Id, Employee_Name, Address} etc. License_Number and Passport_Number columns can also identify any row of the table uniquely. Any set of column which contains License_Number or Passport_Number or Employee_Id is a super key of the table. For example: {License_Number, Employee_Name, Address}, {License_Number, Employee_Name, Passport_Number}, {Passport_Number, Employee_Name, Address, License_Number}, {Passport_Number, Employee_Name}, {Passport_Number, Employee_Id} etc.

  • Foreign Key: In a relationship between two tables, a primary key of one table is referred as a foreign key in another table. Foreign key can have duplicate values in it and can also keep null values if column is defined to accept nulls.

Example: Employee_Id (primary key of Employee table ) is a foreign key in Salary table.

SQL DBA Course with SQL Azure Database & Certification

SQL DBA Course Includes:
* SQL Server T-SQL
* Performance Tuning
* Clustering
* Always On Availability
* Certifications (70 – 764, 765)
* SQL Azure Databse (Developer, Admin)

Register today for LIVE Online Training
http://www.sqlschool.com/SQLDBA-Online-Training.html

Call us today: +91 90 1434 1434 [Toll Free]

#SQLDA #DBA #Azure #AzureAdmin #AzureDatabase #Database #Administration #TSQL #SQL #Training #Online

What is Normalization? 

What is Normalization? 

Normalization is a database design technique which organizes tables in a manner that reduces redundancy and dependency of data.

It divides larger tables to smaller tables and link them using relationships.

In this tutorial, you will learn-

The inventor of the relational model Edgar Codd proposed the theory of normalization with the introduction of First Normal Form and he continued to extend theory with Second and Third Normal Form. Later he joined with Raymond F. Boyce  to develop the theory of Boyce-Codd Normal Form.

Theory of Data Normalization in Sql is still being developed further. For example there are discussions even on 6th Normal Form. But in most practical applications normalization achieves its best in 3rd Normal Form. The evolution of Normalization theories is illustrated below

1st Normal Form >> 2nd Normal Form >> 3rd Normal Form >>4th Normal Form >>  5th Normal Form >>6th Normal Form

Database Normalization Examples –

Assume a video library maintains a database of movies rented out. Without any normalization all information is stored in one table as shown below.

Further We shall discuss on different normal forms in detailed: