Saturday, 4 March 2017

Connect to the SQL Server Default and Named Instances

Connect to the SQL Server Default and Named Instances:



A system can run multiple SQL Server instances. Only one default instance whose name is "MSSQLSERVER" and more than one named instances whose name was given at the time of instance installation.

First, find out what are all the instances that you are running in your system. Go to start, all programs, open the installation folder of "Microsoft SQL Server 2012", go to Configuration Tools, click on "SQL Server Configuration Manager". Shows the same steps below.

Setup an Account as Administrator in Windows Operating System

Setup an Account as Administrator in Windows Operating System:


The following post assumes that you are using Windows 7 operating system.

First, Go to Control Panel. Click on "Add or remove user accounts" as shown in below screen.


If you already set an account as Administrator with a password, then you don't need to proceed further. Example: the user "Chreddy" in below image.

Friday, 3 March 2017

How to Install SQL Server 2012

Installation of SQL Server 2012:



First, setup an administrator account with a password in your system. Click here to see how to set an account as administrator and set the password in windows operating systems.

Second, download the SQL Server 2012 Enterprise Evolution Edition. Click here to see how to download the SQL Server 2012 Enterprise Evaluation Edition.

Once you have the extracted files, you will see an installation file (setup.exe) as shown in below image.


Double click on setup file to open installation, click 'yes' to open the window of SQL Server Installation centre as shown in below image.

Download SQL Server 2012 Enterprise Evaluation Edition

Download SQL Server 2012 Enterprise Evaluation Edition:


We can download the SQL Server 2012 Enterprise Evaluation Edition from the link below.

Go to the following site and Click on the Download as shown in below image.
https://www.microsoft.com/en-in/download/details.aspx?id=29066



Thursday, 23 February 2017

Integrity and Manipulation Components in Relational Model

What is the Integrity and Manipulation in Relational Model?

Integrity: -- It forces the business rules and uniqueness of data.
1. Candidate Key - It is an attribute, which helps to identify an individual tuple in a relation.
2. Primary Key - It is an attribute (one or more attributes), that help to identify an individual tuple in a relation. We can also call this attribute as candidate key. But this attribute will not allow duplicate data values and NULL (unknown data). This is the entity integrity rule.
3. Foreign Key - This is the key (child relation) which stores data that should be available in one of the attribute (primary key) in another relation (parent relation). This is the referential integrity rule.

Manipulation: -- The manipulation defines reading (SELECT) and Writing (INSERT, UPDATE & DELETE) the data on a relation. Two parts in the manipulation.
1. Relational Algebra: It is a collection of operators which can be applied among the relations.
2. Relational Assignment Operator: It will take the output of "Relational Algebra" and assign it to another relation.

Relational Algebra: -- Restrict data; Project data, Product, Union; Intersect & Difference --> These operators will produce a relation as output.

Restrict: - Fetch the specific tuples from a relation. It is nothing but applying WHERE condition on a relation. It returns a relation with tuples which satisfy the particular condition.
Project: -- Defines what attributes that we have to display. It returns a relation with all the tuples with specified attributes.
Product: -- It returns a relation that contains all possible tuples with the combinations from two or more relations. This operation is known as Cartesian product (Cross Product, Cross Join and Cartesian Join).
Union: -- It returns a relation with all tuples that appear in either or both relations. It avoids the duplicate tuples.
Intersect: -- It returns a relation with all tuples that appear in both relations.
Difference: -- It returns a relation with all the tuples in first relation which are not available in second relation
Relational Assignment Operator: The below example shows who to assign a relation to another relation.


SELECT * INTO #RelationProducedFromHelloRelation from Hello JOIN Hello1 ON Hello.id = Hello1.id


Generate the INSERT scripts from a table in PostgreSQL

Question: I want to generate INSERT scripts from a table data.

Answer: We can use the following query to pull the existing data and prepare the INSERT statements.

SELECT 'INSERT INTO schemaName.tableName SELECT
'''||name||''',
'''||value||''';
' from schemaName.tableName ;

1. Change the schema and table name.
2. Add every column as shown in query. The name and value are two columns.

ERROR: Record "OLD" is not assigned yet or ERROR: Record "NEW" is not assigned yet


The following error will get while calling the trigger function by a trigger in postgresql. The trigger function may be using one of these variables OLD and/or NEW.

Error: record "old" is not assigned yet
Error: records "new" is not assigned yet

Solution: Use the "FOR EACH ROW" in your trigger. The OLD and NEW variables are only available for UPDATE operation. Only "NEW" variable is available for INSERT operation. Only "OLD" variable is available for DELETE operation.