Re: T-SQL is not quite there yet

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



DWalker07 (none@xxxxxxxx) writes:
1) Calls to stored procedures can't be nested. That is, one stored
procedure can't do an Insert Into <Table> Exec <StoredProc1> if
StoredProc1 does the same thing to insert data from StoredProc2. Why
not?

My assumption is that they piggyback on the output buffer, and it is
a trick that can only be performed once.

In any case, see http://www.sommarskog.se/share_data.html for alternatives.
In this article I also discuss other problems with INSERT-EXEC and
shows that this is not a very good construct, with or without this
restriction.

3) It's hard to create indexes on table variables. It can be done by
creating a Unique constraint or a Unique Clustered constraint on one set
of columns, but sometimes this is not what we want. I often want non-
unique indexes, and I prefer to create one index per column.

Keep in mind that table variables are declared entities and such
they are static. It makes perfect sense that you can add indexes on
them later. Possibly the syntax could permit you declare non-unique
indexes on it. Personally, I've never seen this much of an issue. Since
a non-clustered index includes the clustered index key this means that
adding the primary key to an extra index has no cost, as long as the PK
is clustered.

4) In spite of what I remember Microsoft saying way back when -- that
they would consider it a bug if table variables perform worse than
temporary tables -- I have found many situations where table variables do
perform slower.

Certainly. Inserting into table variable precludes parallelism. And
since table variales do not have statistics, the optimizer has
less information than with a temp table which has statistics. Which means
that you get better chances for better query performance with temp tables.
(But with temp tables you can lose on recompiles instead.)

5) "Remote table-valued function calls are not allowed". Why not? Just
to frustrate us?

Overall, there are a lot of restrictions with linked servers. For instance,
neither you cannot pass XML over linked servers.

I assume a lot of this has to do with that the linked server may not
support these features. Keep in mind that from SQL Server's perspective,
the linked server may be Oracle, MySQL or a home-grown data source.
In fact, I don't think there is any support in OLE DB at all for table-
valued functions, and OLE DB is what SQL Server uses the access the linked
server.

Now, since surely over 90% of all linked server in this world, is another
SQL Server instance, one could surely wish that SQL Server had special
support for this.

I realize that T-SQL is not yet a first class language, but nit-picky
things like "Can't nest Insert Into calls on stored procedures" and
"can't create temp tables in user-defined functions" and "Remote table-
valued function calls are not allowed" all conspire to make using SQL
that much harder.

Again, I like to stress that the issue on remote table-valued function
is not a language issue. There is simply no infrastructure the language
can use.

--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

.



Relevant Pages

  • Re: T-SQL is not quite there yet
    ... StoredProc1 does the same thing to insert data from StoredProc2. ... But I have seen huge speedups with temp tables when I have added indexes ... I assume a lot of this has to do with that the linked server may not ... another SQL Server instance, one could surely wish that SQL Server had ...
    (microsoft.public.sqlserver.programming)
  • Re: Linked Server
    ... SQL instance to be able to delegate on your behalf to the 2nd SQL Server ... [Create Linked Server Object on Middle Server] ... set up its login to use delegation. ...
    (microsoft.public.sqlserver.server)
  • Re: MAS90
    ... To set up a linked server from SQL Server 2000 to MAS90 using Enterprise ...
    (comp.databases.ms-access)
  • Re: Support team security
    ... to view Linked Server properties (this is a tool requirement not a SQL ... Jasper Smith (SQL Server MVP) ... SQL Server Agent Job Schedule and Job history ...
    (microsoft.public.sqlserver.security)
  • Re: SQL Server 2000 linked server problem
    ... of SQL Server 2000 to fix some known bugs on the SQL Server side. ... the both two SQL Server instances (local and linked server), ... If Windows Firewall or other third party firewall is used, ...
    (microsoft.public.sqlserver.connect)