Showing posts with label gurus. Show all posts
Showing posts with label gurus. Show all posts

Wednesday, March 28, 2012

Opening Table in Management Studio is very slow

Dear Gurus

When I open a large table (say more than 1,000,000 Rows) in the SSMS by right clicking on the table name, it takes a very big time to fully open the table.More than 20 minutes for 1,000,000 records on a local instance.

SQL Server 2000 EM was extremely faster. Does any one knows a work around?

I need to be able to view and edit the data in SSMS.

Thanks in advance.

Parviz

I do not suggest ever opening a large table like this and editing the data through management studio. It is better to write queries to view the data as needed, and dml statements to update the data as needed.
Tim

Friday, March 23, 2012

Opendatasource for text file

Ok .. Gurus ... here's my problem

I am able to successfully run a opendatasource query against a flat file from SQL Server. However the problem I am facing is that the resultset that is returned has a line as one column and one row ... is there any way i can get the opendatasource query to recognize tabs as column seperators ??Why not just bcp it in to a table?|||coz brett .. i ve got a huge problem with BCP ...

It needs a table structure to be defined ... and i dont have that luxury ... I need to take any flat file ... check if it meets my requirements and if it does only then load it into a table ... otherwise display an error...

The data files are going to come in from different locations ... either as a flat file or as a excel file ... dont have control on that ... have got to check the files coming in for different validity criterion ...

The files coming in might be having more columns than needed ... and i need to ignore those.

Hope you get an idea of the mess I am in ... need help desperately ...|||EXCEL or csv?

BIG difference...

I would think about this

CREATE TABLE myTable99(Col1 varchar(8000))
GO

And bcp everything in to that...then interogate the data...

and you say you have a final destination table anyway...

how do get the data from these different source to match in tyhe first place...do they all have different layouts?

How do you know what layout to use?

Do you want the pong software back for your new laptop?|||Either Excel or Tab Delimited Excel file ...

And bcp everything in to that...then interogate the data...

same thing as using a linked server ... forgetting about the performance part ...

final destination table is defined but data is going to come from different sales people ... some have access .. some have msde ... some have excel ...

heres what i have till now

CREATE TABLE [File_Column_Format] (
[DataSource] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[ColName] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[DataType] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[length] [int] NULL ,
CONSTRAINT [PK_File_Column_Format] PRIMARY KEY CLUSTERED
(
[DataSource],
[ColName]
) ON [PRIMARY]
) ON [PRIMARY]
GO

CREATE TABLE [FileNameFormats] (
[DataSource] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Format_type] [varchar] (256) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

These are the tables i am using to define what I want ... and validate the files I m being sent ... i can validate the excel files using this method ... but what about flat text files ?|||Are you using a config table to define the different file structures?

Also, How many different people?

Can't you just distribute an Access database and have it create the same csv file from everyone?

What a nightmare...

My sympathies...|||Originally posted by Brett Kaiser
Are you using a config table to define the different file structures?


Not for file structures .. but only for the table that the data is going into ... if any of the fields do not match the datatype or size described for it ... throw an error expressing .. row no and col no.
Originally posted by Brett Kaiser
Also, How many different people?

Say about 250

Originally posted by Brett Kaiser
Can't you just distribute an Access database and have it create the same csv file from everyone?

Can you elaborate on that ?

Originally posted by Brett Kaiser
What a nightmare...


[Wakes Up] Scream [/Wakes up]

[Goes back to sleep]zzzzzzzzzz[/Goes back to sleep]
Originally posted by Brett Kaiser
My sympathies...

Really need that ... and I thought ETL was easy :)|||I would just recreate the final destination table in Access...give them a form...so they can do their data entry...have Access export the data as a csv...place the mdb in a read only folder on the server

let them get copies from that location...have a single location that the need to deliver the data..

(they're mailing it to you right?)

That way they can't screw it up...because they will

Saturday, February 25, 2012

Only for SQL GURUS - Calling external procedures from Functions

I am using SQL Server 2005 Developer Edition. I am working on a conversion project from Oracle to SQL Server 2005.

As part of this, in order to replicate Oracle sequence functionality in SQL Server, the design called for writing a function that would accept a parameter , say sequence name. There will be a user table, say, SEQUENCE_GENERATOR with the following structure.

Column Name Data Type Nullability
-- -
Sequence_Name varchar(50) N
Last_Number int N

Everytime before generating the next sequence this function would be called. It would do the following : -

-
Select @.Last_Number = Last_Number
from SEQUENCE_GENERATOR WITH (UPDLOCK)
WHERE Sequence_Name = <func parameter passed i.e. Sequence Name>

SET @.Last_Number = @.Last_Number +1

UPDATE SEQUENCE_GENERATOR
SET
Last_Number = @.Last_Number
WHERE Sequence_Name = <func parameter passed i.e. Sequence Name>

RETURN
@.Last_Number
Since we are fetching the value of Last_Number(by calling the function) before inserting into our tables, we do not want users simultaneously accessing the same sequence to end up with PK violations and hence the use of UPDLOCK hint.

Now the real problem: -

Since the above three steps are a DML operation excepting the RETURN clause, we cannot do it in a function. However we can call an external stored procedure that does the above UML operations to accept the parameter and then return an output value. This output value would then be returned by the function.

Now I would like to know if the above approach is possible with external sps as I have no prior experience in this. Also, can someone point important resources where I can code the above thing in C++...

Thanks & Regards
Imtiaz

Before I get to the answer...

1. In practice sequence tables are a huge headache in any database design, I find they're more common in the Oracle world than any other, especially in large database designs that required a federated/distributed/replication model. If you can avoid a sequence table, consider using uniqueidentifier columns for PKs instead, they will remove a lot of headache (read: labor hours) and simplify software design at all levels.

2. Locking (table or otherwise) just creates artificial contention, if 1000 clients all decided to create a record at the same time they'd all have to stand in line. *owe*

3. In your sequence table you might consider using a seeded identity column for the PK, and leave the 'sequence name' as a regular data value. You could then write a UDF (function) in sql server that simply inserted the sequence name into the sequence table, and upon completion you acquire the generated number via @.@.IDENTITY (look this up in Books Online if you're not familiar with it already). This will help avoid the locking (which is hell on performance) and still get everything contained within sql server (no need to go the xp route). This is an option so long as the rest of the solution doesn't rely on a contigious set of numbers for a given sequence name (table?).
To answer your question, though, an extended stored procedure (xp/xsp) is implemented as a standard C dll, so you could implement it in C++ so long as you had cdecl exports sql server could consume.

Also, the registration process is tacky (look up sp_addextendedproc) since it requires access to the master table, but yes you can do what you want using an xp and a little elbow grease.

See: Creating an Extended Stored Procedure (MSDN)

Hope that helps,
Shaun

|||The logic that you have below is not quite correct unless you enclose the statements in a transaction. Without a transaction, the UPDLOCK will be released after the SELECT statement completes.

Select @.Last_Number = Last_Number
from SEQUENCE_GENERATOR WITH (UPDLOCK)
WHERE Sequence_Name = <func parameter passed i.e. Sequence Name>

SET @.Last_Number = @.Last_Number +1

UPDATE SEQUENCE_GENERATOR
SET
Last_Number = @.Last_Number
WHERE Sequence_Name = <func parameter passed i.e. Sequence Name>

RETURN
@.Last_Number

A more concise way of writing this in SQL Server is to use the UPDATE statement extension like:

UPDATE SEQUENCE_GENERATOR
SET @.Last_Number = Last_Number = Last_Number + 1
WHERE Sequence_Name = <sequence name>

Having said this, it is still not possible to perform data modifying operations from within UDFs. You can write an extended stored procedure. But that is more trouble actually. It can easily lead to concurrency issues, poor performance etc. You will also have to use bound connections. You could still go this route but be aware of the risks especially in a OLTP environment. You can use Visutal Studio templates to create the stubs required for implementing extended stored procedures. In any case, I would recommend against converting Oracle code verbatim. Identity provides a much faster and efficient mechanism to generate sequence numbers. If you need the sequence mechanism then why not implement it as a stored procedure and call it from within the proc requiring it. This is much more scalaeble way to implement it in TSQL.|||Shaun and Uma

The solutions you have given me instead of using external stored procedures I am aware of that. The application would run on Oracle or SQL Server backedn and the idea is to have most of the things as close as possible. I know this can be achieved by SPs but we desperately need functions to do that.

Uma
The reason we have UPDLOCK hint is for concurrency issues.

Now how can we write T-SQL code in C++ is my question. where do I start with?|||I am still waiting for some inputs on this...The problem is how do I start a xaction, access the database in extended procedure.

Regards
Imtiaz|||

Shaun Wilson wrote:

See: Creating an Extended Stored Procedure (MSDN)

Also

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odssql/ods_6_con_01_22sz.asp

and

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odssql/ods_6_con_01_22sz.asp

Sync the toc on their website, all the docs you need are there. If all else fails you might consider using MSDTC as a transaction coordinator between the 'client', your xp and sql server.

Only for Gurus -- Analysis MDX Query help needed

I need a expression to get the name of the Member of a dimension.
For example .. if I have a Time Dimension ... and Child in hierarchy are Months.. I would like the result as
January
February
.....
December
Any Ideas ?http://www.winnetmag.com/Article/ArticleID/16311/16311.html

HTH