Venkatesan Prabu MCITP,MCAD,MCTS,CCNA. Worked as a ProjectLead(Senior .Net developer,SQL DBA). Now, Managing Director of KAASHIV INFO TECH, Chennai This Blog aims in serving the community in a better way. This blog is read by developers in 159 countries with average of 400 hits per day. Please post your valuable suggestions and hold my hand to serve the community. Lets make a new world with good thoughts and good minds....... This blog serves the SQL server community all over the world.
28.6.08
SSIS Package error
I have tried to work with Script task but while running the application I have got some errors in executing the same. Below is the error.
TITLE: Package Validation Error
------------------------------
Package Validation Error
------------------------------
ADDITIONAL INFORMATION:
Error at Script Task: The task is configured to pre-compile the script, but binary code is not found. Please visit the IDE in Script Task Editor by clicking Design Script button to cause binary code to be generated.
(Microsoft.DataTransformationServices.VsIntegration)
Procedure followed:
1. I have created a variable “Var1” in the variables window with the scope as “Script task”.
2. Dragged the script task and put the same in the designer window.
3. Double clicking the script task and click “script”, we can see the Script details in the right pane. 4. In Readwritevariables, I have specified “User::Var1”
5. Clicked “Design Script” and written a small VB.net code snippet in the script main function.
Dts.Variables("Var1").Value = 20
MsgBox(Dts.Variables("Var1").Value)
Saved the application and tried to execute it. I got the above error.
Solution to resolve the problem:
1. The problem is due to binary code generation from the VB.net code. Double click script task, script and check the “precompileScriptintoBinarycode” should be true.
2. May be the problem is with the VB.net code. Please check the syntax of the code.
3. Else, the problem is with the Service pack. If you have older version of SQL Server 2005, you can’t have that option of converting into binary codes. In this case, you need to download the SQL server FIX from Microsoft site.
http://www.microsoft.com/downloadS/details.aspx?FamilyID=2ba43893-ef6b-4019-9e7d-d8cc6c7b905d&displaylang=en
I have installed x86 version, now its working fine.
Happy Learning!!!.
Regards,
Venkat
27.6.08
SQL Server 2005 connection error
Once Sql server 2005 – Database (SQLExpress) is installed in our machine. If we try to connect to the local or remote server, we usually get an error in connecting the database. Below is the error string,
TITLE: Connect to Server
------------------------------
Cannot connect to Server.
------------------------------
ADDITIONAL INFORMATION:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) (Microsoft SQL Server, Error: -1)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=-1&LinkId=20476
I have searched in web for a proper solution. But, I didn’t find any proper solution and wish to log the solution in my blog.
As per the error, the problems are due to,
v Server’s remote connection is disabled.
v Protocol disabled for remote connection (TCP/IP).
v Alias creation or alias mismatch.
Solution:
Enabling Remote connection and protocol:
v Click Start, point to Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Surface Area Configuration.
v On the SQL Server 2005 Surface Area Configuration page, click Surface Area Configuration for Services and Connections.
v On the Surface Area Configuration for Services and Connections page, expand Database Engine, click Remote Connections, click Local and remote connections, click the appropriate protocol to enable for your environment, and then click Apply.
v On the Surface Area Configuration for Services and Connections page, expand Database Engine, click Service, click Stop, wait until the MSSQLSERVER service stops, and then click Start to restart the MSSQLSERVER service.
Check the screen shot for the reference,
Resolving Alias Problem:
v Click Start, point to Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, Click SQL Server configuration manager.
v Click “Aliases” you can see your aliases in the right pane.
v If your server’s name aliases is there just double click it and check your “server”, “port number” and “alias name”
v If there is no alias you need to create an alias. Provide your server name (machine name). Right click you’re my computer and you can get the name.
v You need to specify the port number check with 5000 and 20000 port numbers. Most probably it will work and it’s specific to your client.
v Now just click “Ok” button.
v Try to connect you SQL server database engine.
v Now it will work… cool… No worries.
Regarding creation of exceptions for your newly installed SQL Server 2005. You can check this KB, http://support.microsoft.com/kb/914277
Happy learning!!!
Regards,
Venkatesan Prabu . J
26.6.08
Finding subdirectories and directory depth in SQL Server
EXEC master.sys.xp_dirtree 'E:\Test'
On executingh the query above, we will get below output,
1. Subdirectory – Shows all subdirectories inside the given path or directory.
2. Depth – Depth of the subdirectory from the given path or directory.
Foreign key relationship in sql server
This constraint is used to map a particular column in the child table with a primary key column in the parent table. Consider my scenario, am having an employee table and it will be having empid as primary key (Unique reference to identify an employee) , am having empProjects which will hold project id as the primary key.
I need to check, In which project an employee is allocated? Or what are the projects assigned for this particular employee?
The relation ship between these two tables is One to Many relationship (An employee can work in more than one project).
To retrieve the result set we need to have a foreign key relation ship between the employee table and empProjects table, a column empid should be created in empProjects table and it should refer the primary table “Employee”.
Let’s see a small example; I am trying to create two tables VenkatA, VenkatB. Id in the second table is referencing the ‘id’ column in the primary table.
create table venkatA(id int,[name] varchar(100))
create table venkatB(id int references venkatA(id),designation varchar(100))
OOPS, On executing the query above, we will get an exception.
There are no primary or candidate keys in the referenced table 'venkatA' that match the referencing column list in the foreign key 'FK__venkatB__id__7BB05806'.
It’s because of the column ‘id’ in the primary table. It’s mandatory to declare that particular columns as primary or candidate key.
create table venkatA(id int primary key,[name] varchar(100))
create table venkatB(id int references venkatA(id),designation varchar(100))
On executing the query above, you will get the second table referencing the first one.
Happy Learning!!!
Regards,
Venkatesan Prabu .J
Retrieving physical location of your MDF and LDF file in sql server
Is it possible to retrieve the physical location of my data file and log file?
I am struck up with retrieving details for data and log file location of our existing databases and found that the key table is located in the master databases. Below is the query to retrieve that information,
select * from [master].[sys].[master_files]
On executing the query above, we will get the below result set,
DECLARE @sql_path NVARCHAR(256) ;
SELECT @sql_path = SUBSTRING([physical_name], 1, CHARINDEX(N'master.mdf', LOWER([physical_name])) - 1)
FROM [master].[sys].[master_files]
WHERE [database_id] = 1
AND [file_id] = 1 ;
print @sql_path
16.6.08
My travel to Sydney, Australia
OOPS, after waiting for 6 hours in malaysian airport, i have got my next flight to sydney.
It's really a cool place to work.
Endrum,
Venkat
Error message "Interface not registered"
Problem faced in SSIS package:
Today, I've found a peculiar problem in opening my SSIS package. I've tried to create a new SSIS package. OOPS, I found a message box showing "Error message "Interface not registered" ". After clicking Ok button, i didn't got a new package instead the IDE stood mum :-)
Reason for the problem:
1. Your previous installation files were creating some issues. It's because of the improper cleaning of your machine registry for your new installation.
2. Improper installation of your MSXML files.
Solution:
Try registering MSXML using the following commands in the command prompt (CMD)
a. regsvr32 msxml3.dll
b. regsvr32 msxml6.dll
Happy Learning!!!
Regards,
Venkatesan Prabu . J
3.6.08
T-SQL to fetch the tables with out primary key in the database
Code Snippet to retrieve the table without primary key |
select name as TableWithoutPrimaryKey from sys.sysobjects where type='U' and objectproperty(id,'TableHasPrimaryKey') = 0 |
I've used Object property to fetch this information.
Happy Learning!!!
Regards,
Venkatesan prabu. J
SQL Teaser 2 - More magics in SQL Server
Code Snippet |
SET ROWCOUNT 0 DECLARE @ int SET @ =6 IF @@ROWCOUNT = 1 PRINT 'yes' ELSE PRINT 'no' PRINT @@rowcount |
The output is Yes and 0. I've dig for the answer and found it. The reason for "Yes" is, in the previous statement i have set the value SET @ =6 and after that am checking the @@rowcount. Obviously, it's value is 1. Thats why we got the output as "Yes" and in the last print statement we dont have any updation of rows. So its result shows 0.
Happy learning!!!
Regards,
Venkatesan prabu . J
SQL Teaser - Some magics in SQL Server
What could be the output?
Code Snippet |
SET ROWCOUNT 0 DECLARE @ int SET @ =6 print @ |
I thought the @ symbol should come in the default declaration part and the above snippet should throw an error. OOPS, its not the case @ is considered as a variable.
Happy Learning!!!
Regards,
Venkatesan Prabu . J
My T-SQL Gallery @code.msdn.microsoft
Created my own T-SQL Gallery in Microsoft site. Do visit the same and share your feedback,
http://code.msdn.microsoft.com/VenkatSQLSample/Thread/List.aspx
Thanks and Regards,
Venkatesan Prabu .J
SQL Server Interview questions - Part 1
Null means no entry has been made. It implies that the value is either unknown or undefined.We should avoid permitting null values because Column with NULL values can't have PRIMARY KEY constraints. Certain calculations can be inaccurate if NULL columns are involved.
What is SQL whats its uses and its component ?
The Structured Query Language (SQL) is foundation for all relational database systems. Most of the large-scale databases use the SQL to define all user and administrator interactions. It enable us to retrieve the data from based on our exact requirement. We will be given a flexibility to store the data in our own format.
The DML component of SQL comprises four basic statements:
* SELECT to get rows from tables
* UPDATE to update the rows of tables
* DELETE to remove rows from tables
* INSERT to add new rows to tables
What is DTS in SQL Server ?
Data Transformation Services is used to transfer the data from one source to our required destination. Considering am having some data in sql server and I need to transfer the data to Excel destination. Its highly possible with dialogue based tool called Data Transformation services. More customization can be achieved using SSIS. A specialized tool used to do such migration works.
What is the difference between SQL and Pl/Sql ?
Straight forward. SQL is a single statement to finish up our work.Considering, I need some data from a particular table. “Select * from table” will fetch the necessary information. Where as I need to do some row by row processing. In that case, we need to go for Procedural Logic / SQL.
What is the significance of NULL value and why should we avoid permitting null values?
Null means no entry has been made. It implies that the value is either unknown or undefined.We should avoid permitting null values because Column with NULL values can't have PRIMARY KEY constraints. Certain calculations can be inaccurate if NULL columns are involved.
Difference between primary key and Unique key?
Both constraints will share a common property called uniqueness. The data in the column should be unique. The basic difference is,
· Primary key won’t allow null value. Whereas, unique key will accept null value but only one null value.
· On creating primary key, it will automatically format the data inturn creates clustered index on the table. Whereas, this characteristics is not associated with unique key.
· Only one primary key can be created for the table. Any number of Unique key can be created for the table.
Select Statement in SQL Server
String Functions in sql server
SQL Server Interview Question - Part 2
What is normalization?
Normalization is the basic concept used in designing a database. Its nothing but, an advise given to the database to have minimal repetition of data, highly structured, highly secured, easy to retrieve. In high level definition, the Process of organizing data into tables is referred to as normalization.
What is a stored procedure:
Stored procedures are precompiled T-SQL statements combined to perform a single task of several tasks. Its basically like a Macro so when you invoke the Stored procedure, you actually run a set of statements. As, its precompiled statement, execution of Stored procedure is compatatively high when compared to an ordinary T-SQL statement.
What is the difference between UNION ALL Statement and UNION ?
The main difference between UNION ALL statement and UNION is UNION All statement is much faster than UNION,the reason behind this is that because UNION ALL statement does not look for duplicate rows, but on the other hand UNION statement does look for duplicate rows, whether or not they exist.
Example for Stored Procedure?
They are three kinds of stored procedures,1.System stored procedure – Start with sp_2. User defined stored procedure – SP created by the user.3. Extended stored procedure – SP used to invoke a process in the external systems.Example for system stored proceduresp_helpdb - Database and its propertiessp_who2 – Gives details about the current user connected to your system. sp_renamedb – Enable you to rename your database
What is a trigger?
Triggers are precompiled statements similar to Stored Procedure. It will automatically invoke for a particular operation. Triggers are basically used to implement business rules.
What is a view?
If we have several tables in a db and we want to view only specific columns from specific tables we can go for views. It would also suffice the needs of security some times allowing specfic users to see only specific columns based on the permission that we can configure on the view. Views also reduce the effort that is required for writing queries to access specific columns every time.
What is an Index?
When queries are run against a db, an index on that db basically helps in the way the data is sorted to process the query for faster and data retrievals are much faster when we have an index.
What are the types of indexes available with SQL Server?
There are basically two types of indexes that we use with the SQL ServerClustered -
1. It will format the entire table, inturn physically sort the table.
2. Only one clustered index can be created for a table.
3. Data will be located in the leaf level.
4. By default, primary key will create clustered index on the table.
Non-Clustered Index
1. It wont touch the structure of the table.
2. It forms an index table as reference to the exact data.
3. A reference to the data will be located in the leaf level.
4. For a table, we can create 249 non clustered index.
Happy Learning!!!
Regards,
Venkatesan Prabu .J
SQL Interview question
Extent Vs Page?
Pages are low level unit to store the exact data in sql server. Basically, the data will be stored in the mdf, ldf, ndf files. Inturn, pages are logical units available in sql server.The size of the page is 8KB.
Eight consecutive pages will form an extent 8 * 8KB = 64KB.
Thus I/O level operation will be happening at pages level.The pages will hold a template information at the start of each page (header of the page).
They are,
1. page number,
2. page type,
3. the amount of free space on the page,
4. the allocation unit ID of the object that owns the page.
Extents will be classifed into two types,
1. Uniform extents
2. Mixed extents
Uniform Extents:It occupied or used by a single object. Inturn, a single object will hold the entire 8 pages.Mixed
Extents:Mulitple objects will use the same extent. SQL Server will allow a max of eight objects to use a shared extent.
Property of SQL Server :Initally if an object is created, sql server will allocate the object to the mixed extent and once if the size reaches 8 pages and more... immediately, a new uniform extent will be provided for that particular object.
Herecomes, our fragmentation and reindexing concepts.