Monday, March 19, 2012
Applying criteria at the start of a series of views
... from view4; View 4 is select ... from view3 etc.
That all works fine, but what this does is include all of the data from
whatever tables are involved even though I need a subset. My typical
scenario is that the majority of the data are in the table(s) involved in the
initial view(s)
What I would like to do is pass the necessary parameters to the view(s)
involved so as to limit the amount of data that gets passed along. I'm still
learning the right way to do things in SQL, so I appreciate any insights that
anyone can provide.
TIA,
John"DevalilaJohn" <DevalilaJohn@.discussions.microsoft.com> wrote in message
news:098BB47D-453F-4B0A-A2E2-B843B10F30AA@.microsoft.com...
>I have a series of views that provide a final result set e.g view 5 is
>select
> ... from view4; View 4 is select ... from view3 etc.
> That all works fine, but what this does is include all of the data from
> whatever tables are involved even though I need a subset. My typical
> scenario is that the majority of the data are in the table(s) involved in
> the
> initial view(s)
> What I would like to do is pass the necessary parameters to the view(s)
> involved so as to limit the amount of data that gets passed along. I'm
> still
> learning the right way to do things in SQL, so I appreciate any insights
> that
> anyone can provide.
>
SQL Server will pass where-clause predicates down through views to the base
tables if it can. If the column in a view is the result of an expression,
however, this won't work.
David
Applying criteria at the start of a series of views
... from view4; View 4 is select ... from view3 etc.
That all works fine, but what this does is include all of the data from
whatever tables are involved even though I need a subset. My typical
scenario is that the majority of the data are in the table(s) involved in the
initial view(s)
What I would like to do is pass the necessary parameters to the view(s)
involved so as to limit the amount of data that gets passed along. I'm still
learning the right way to do things in SQL, so I appreciate any insights that
anyone can provide.
TIA,
John
"DevalilaJohn" <DevalilaJohn@.discussions.microsoft.com> wrote in message
news:098BB47D-453F-4B0A-A2E2-B843B10F30AA@.microsoft.com...
>I have a series of views that provide a final result set e.g view 5 is
>select
> ... from view4; View 4 is select ... from view3 etc.
> That all works fine, but what this does is include all of the data from
> whatever tables are involved even though I need a subset. My typical
> scenario is that the majority of the data are in the table(s) involved in
> the
> initial view(s)
> What I would like to do is pass the necessary parameters to the view(s)
> involved so as to limit the amount of data that gets passed along. I'm
> still
> learning the right way to do things in SQL, so I appreciate any insights
> that
> anyone can provide.
>
SQL Server will pass where-clause predicates down through views to the base
tables if it can. If the column in a view is the result of an expression,
however, this won't work.
David
Applying criteria at the start of a series of views
t
... from view4; View 4 is select ... from view3 etc.
That all works fine, but what this does is include all of the data from
whatever tables are involved even though I need a subset. My typical
scenario is that the majority of the data are in the table(s) involved in th
e
initial view(s)
What I would like to do is pass the necessary parameters to the view(s)
involved so as to limit the amount of data that gets passed along. I'm stil
l
learning the right way to do things in SQL, so I appreciate any insights tha
t
anyone can provide.
TIA,
John"DevalilaJohn" <DevalilaJohn@.discussions.microsoft.com> wrote in message
news:098BB47D-453F-4B0A-A2E2-B843B10F30AA@.microsoft.com...
>I have a series of views that provide a final result set e.g view 5 is
>select
> ... from view4; View 4 is select ... from view3 etc.
> That all works fine, but what this does is include all of the data from
> whatever tables are involved even though I need a subset. My typical
> scenario is that the majority of the data are in the table(s) involved in
> the
> initial view(s)
> What I would like to do is pass the necessary parameters to the view(s)
> involved so as to limit the amount of data that gets passed along. I'm
> still
> learning the right way to do things in SQL, so I appreciate any insights
> that
> anyone can provide.
>
SQL Server will pass where-clause predicates down through views to the base
tables if it can. If the column in a view is the result of an expression,
however, this won't work.
David
Sunday, March 11, 2012
Apply policy to restrict records
It is possible to restrict the records viewed by an user
using policies instead of creating a view?
If it is possible, how can i do it?
Best regardsCC
You cannot restrict 'some rows' from viewing without creation of view.
You can deny SELECT on the whole table not just on some rows.
Why do you want to that without a view? It is a classic for such kind of
operations.
"CC&JM" <anonymous@.discussions.microsoft.com> wrote in message
news:1cead01c45399$fdffadb0$a301280a@.phx.gbl...
> Hello,
> It is possible to restrict the records viewed by an user
> using policies instead of creating a view?
> If it is possible, how can i do it?
> Best regards|||Hi Uri,
Someone ask me this situation and i told him that it
wasn't possible to do it but... never knows and i need to
ask it.
Thanks a lot,
Best regards
>--Original Message--
>CC
>You cannot restrict 'some rows' from viewing without
creation of view.
>You can deny SELECT on the whole table not just on some
rows.
>Why do you want to that without a view? It is a classic
for such kind of
>operations.
>
>"CC&JM" <anonymous@.discussions.microsoft.com> wrote in
message
>news:1cead01c45399$fdffadb0$a301280a@.phx.gbl...
>> Hello,
>> It is possible to restrict the records viewed by an user
>> using policies instead of creating a view?
>> If it is possible, how can i do it?
>> Best regards
>
>.
>
Wednesday, March 7, 2012
application role how query a view whose reference table is in another db?
Hi everybody.
I created an application role in a database (DB1) and gave it all the rights on a view in DB1 which refers to a table located in another db (DB2). I also gave the rights to the app role on a table of DB1
I tried to use this app. role through the sp_setapprole launched by a user (server principal?) which is SQL Server administrator (and local administrator (Win 2003 Server)).
With the following query
SELECT USER_NAME()
I see that the approle is being used.
Than, if I query the table on DB1 everything works, but if I query the view, referring a table in db2 I get following error:
The server principal "NameOfServerPrincipal" is not able to access the database "DB2" under the current security context.
What should I do to make it work?
The table in DB2 has the same schema of the view in DB1 which refers to it.
I put the DB1 TrustWorthy and both the database have the db_chaining option activated.
Any idea on how to solve the problem would be widely appreciated.
Thank you very much.
Vania
Application roles are not designed to work on cross-database scenarios. The following post has a detailed discussion on the topic: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1312863&SiteID=1
If your application relies heavily on cross-database access, I would recommend against using application roles. If you don’ have a choice, you can create a new execution context using EXECUTE AS in a SP. I wrote a small example that hopefully will be useful:
-- We will strat creating a low privielged login
--that will be used for the cross-DB context
-- and disable it to prevent any connection with it
--
CREATE LOGIN crossdb_login WITH PASSWORD = '50m3 p4zzwrd#'
ALTER LOGIN crossdb_login DISABLE
go
-- First we will go to our source DB to create the SP
-- and digitally sign it
--
use db_Source
go
CREATE USER crossdb_user FOR LOGIN crossdb_login
go
-- This SP will run under the 'crossdb_user' context
--
CREATE PROC sp_demo
WITH EXECUTE AS 'crossdb_user'
AS
-- display the token for testing purposes
SELECT * FROM db_Target.sys.user_token
-- select from a table
SELECT * FROM db_Target.dbo.data
go
-- Sign the modul and create a backup of the cert
-- in order to create a login for it
--
CREATE CERTIFICATE signing_cert
ENCRYPTION BY PASSWORD = '50m3 p4zzwrd#'
WITH SUBJECT = 'signing cert'
go
ADD SIGNATURE TO sp_demo
BY CERTIFICATE signing_cert
WITH PASSWORD = '50m3 p4zzwrd#'
go
BACKUP CERTIFICATE signing_cert TO FILE = 'signing_cert.cer'
go
-- Create a copy of the cert in master and a login mapped to it
--
USE master
go
CREATE CERTIFICATE signing_cert FROM FILE = 'signing_cert.cer'
go
CREATE LOGIN signing_cert FROM CERTIFICATE signing_cert
go
-- Now in the target DB we will create the user we need
-- and grant the appropriate permissions
--
use db_Target
go
CREATE TABLE data( value int )
go
CREATE USER crossdb_user FOR LOGIN crossdb_login
CREATE USER signing_cert
go
-- The certificate will be used to vouch for the
-- impersonated context
--
GRANT AUTHENTICATE TO signing_cert
go
-- GRANT SELECT on the table to the impersonated context
--
GRANT SELECT ON dbo.data to crossdb_user
go
-- Test the new signed SP
--
use db_Source
go
CREATE APPLICATION ROLE approle_demo WITH PASSWORD = '@.ppr0l3 d3m00'
go
GRANT EXECUTE ON sp_demo to approle_demo
go
EXEC sp_setapprole 'approle_demo', '@.ppr0l3 d3m00'
go
-- Should fail
-- Msg 916, Level 14, State 1, Line 1
-- The server principal "<<login_name>>" is not able to access the database "db_Target" under the current security context.
--
SELECT * FROM db_Target.dbo.data
go
-- Should succeed
EXEC sp_demo
go
Please let us know if you have any questions.
Thanks,
-Raul Garcia
SDE/T
SQL Server Engine
|||
Thank you so much and forgive me for my late but was on holidays.
Your solution works fine, in fact (I am sure you have no doubts about it).
A more question, please forgive me if it is obvious:
how, from inside the sp_demo, can I get the name of the server principal (domain\user if Windows authentication) which set the application role ? I mean the caller of the setapprole.
Thank you very much.
Vania
application role how query a view whose reference table is in another db?
Hi everybody.
I created an application role in a database (DB1) and gave it all the rights on a view in DB1 which refers to a table located in another db (DB2). I also gave the rights to the app role on a table of DB1
I tried to use this app. role through the sp_setapprole launched by a user (server principal?) which is SQL Server administrator (and local administrator (Win 2003 Server)).
With the following query
SELECT USER_NAME()
I see that the approle is being used.
Than, if I query the table on DB1 everything works, but if I query the view, referring a table in db2 I get following error:
The server principal "NameOfServerPrincipal" is not able to access the database "DB2" under the current security context.
What should I do to make it work?
The table in DB2 has the same schema of the view in DB1 which refers to it.
I put the DB1 TrustWorthy and both the database have the db_chaining option activated.
Any idea on how to solve the problem would be widely appreciated.
Thank you very much.
Vania
Application roles are not designed to work on cross-database scenarios. The following post has a detailed discussion on the topic: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1312863&SiteID=1
If your application relies heavily on cross-database access, I would recommend against using application roles. If you don’ have a choice, you can create a new execution context using EXECUTE AS in a SP. I wrote a small example that hopefully will be useful:
-- We will strat creating a low privielged login
--that will be used for the cross-DB context
-- and disable it to prevent any connection with it
--
CREATE LOGIN crossdb_login WITH PASSWORD = '50m3 p4zzwrd#'
ALTER LOGIN crossdb_login DISABLE
go
-- First we will go to our source DB to create the SP
-- and digitally sign it
--
use db_Source
go
CREATE USER crossdb_user FOR LOGIN crossdb_login
go
-- This SP will run under the 'crossdb_user' context
--
CREATE PROC sp_demo
WITH EXECUTE AS 'crossdb_user'
AS
-- display the token for testing purposes
SELECT * FROM db_Target.sys.user_token
-- select from a table
SELECT * FROM db_Target.dbo.data
go
-- Sign the modul and create a backup of the cert
-- in order to create a login for it
--
CREATE CERTIFICATE signing_cert
ENCRYPTION BY PASSWORD = '50m3 p4zzwrd#'
WITH SUBJECT = 'signing cert'
go
ADD SIGNATURE TO sp_demo
BY CERTIFICATE signing_cert
WITH PASSWORD = '50m3 p4zzwrd#'
go
BACKUP CERTIFICATE signing_cert TO FILE = 'signing_cert.cer'
go
-- Create a copy of the cert in master and a login mapped to it
--
USE master
go
CREATE CERTIFICATE signing_cert FROM FILE = 'signing_cert.cer'
go
CREATE LOGIN signing_cert FROM CERTIFICATE signing_cert
go
-- Now in the target DB we will create the user we need
-- and grant the appropriate permissions
--
use db_Target
go
CREATE TABLE data( value int )
go
CREATE USER crossdb_user FOR LOGIN crossdb_login
CREATE USER signing_cert
go
-- The certificate will be used to vouch for the
-- impersonated context
--
GRANT AUTHENTICATE TO signing_cert
go
-- GRANT SELECT on the table to the impersonated context
--
GRANT SELECT ON dbo.data to crossdb_user
go
-- Test the new signed SP
--
use db_Source
go
CREATE APPLICATION ROLE approle_demo WITH PASSWORD = '@.ppr0l3 d3m00'
go
GRANT EXECUTE ON sp_demo to approle_demo
go
EXEC sp_setapprole 'approle_demo', '@.ppr0l3 d3m00'
go
-- Should fail
-- Msg 916, Level 14, State 1, Line 1
-- The server principal "<<login_name>>" is not able to access the database "db_Target" under the current security context.
--
SELECT * FROM db_Target.dbo.data
go
-- Should succeed
EXEC sp_demo
go
Please let us know if you have any questions.
Thanks,
-Raul Garcia
SDE/T
SQL Server Engine
|||
Thank you so much and forgive me for my late but was on holidays.
Your solution works fine, in fact (I am sure you have no doubts about it).
A more question, please forgive me if it is obvious:
how, from inside the sp_demo, can I get the name of the server principal (domain\user if Windows authentication) which set the application role ? I mean the caller of the setapprole.
Thank you very much.
Vania
Thursday, February 16, 2012
append data to an excel file,
data to an excel file, it seems if it sees that the sheet is available it
creates a new sheet,
I have a logo in my excel file and I want to append the rows below it.JIM
create procedure file_write_text(@.file_name varchar(1000),
@.text varchar(8000),
@.append bit = 0)
as
/*
exec file_write_text 'c:\TEST.XLS','hello'
exec file_write_text 'c:\TEST.XLS',' world',1
*/
declare @.fso int
declare @.ts int
declare @.rv int
exec @.rv = sp_oacreate "scripting.filesystemobject", @.fso OUTPUT, 1
if @.rv <> 0 goto eh
if @.append = 1
begin
--open the text stream for append, will fail if the file doesn't exist
exec @.rv = sp_oamethod @.fso,"opentextfile", @.ts OUTPUT, @.file_name, 8
if @.rv <> 0 goto eh
end
else
begin
--create a new text file, overwriing if necessary
exec @.rv = sp_oamethod @.fso,"createtextfile", @.ts OUTPUT, @.file_name, -1
if @.rv <> 0 goto eh
end
exec @.rv = sp_oamethod @.ts,"write",null ,@.text
if @.rv <> 0 goto eh
exec @.rv = sp_oamethod @.ts,"close"
if @.rv <> 0 goto eh
exec sp_oadestroy @.ts
exec sp_oadestroy @.fso
return 0
eh:
declare @.es varchar(512)
declare @.ed varchar(512)
exec sp_oageterrorinfo null, @.es OUTPUT, @.ed OUTPUT
raiserror(@.ed,16,1)
exec sp_oadestroy @.ts
exec sp_oadestroy @.fso
return 1
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:AFE084C6-4A5F-433D-B693-A3CCEAC70596@.microsoft.com...
>I have a DTS that exports a view to an excel file, is it possible to append
> data to an excel file, it seems if it sees that the sheet is available it
> creates a new sheet,
> I have a logo in my excel file and I want to append the rows below it.
>|||Thanks for the reply Uri, is this for text file or Excel file (xls, not csv)
?
"Uri Dimant" wrote:
> JIM
> create procedure file_write_text(@.file_name varchar(1000),
> @.text varchar(8000),
> @.append bit = 0)
> as
> /*
> exec file_write_text 'c:\TEST.XLS','hello'
> exec file_write_text 'c:\TEST.XLS',' world',1
> */
> declare @.fso int
> declare @.ts int
> declare @.rv int
> exec @.rv = sp_oacreate "scripting.filesystemobject", @.fso OUTPUT, 1
> if @.rv <> 0 goto eh
> if @.append = 1
> begin
> --open the text stream for append, will fail if the file doesn't exist
> exec @.rv = sp_oamethod @.fso,"opentextfile", @.ts OUTPUT, @.file_name, 8
> if @.rv <> 0 goto eh
> end
> else
> begin
> --create a new text file, overwriing if necessary
> exec @.rv = sp_oamethod @.fso,"createtextfile", @.ts OUTPUT, @.file_name, -1
> if @.rv <> 0 goto eh
> end
> exec @.rv = sp_oamethod @.ts,"write",null ,@.text
> if @.rv <> 0 goto eh
> exec @.rv = sp_oamethod @.ts,"close"
> if @.rv <> 0 goto eh
> exec sp_oadestroy @.ts
> exec sp_oadestroy @.fso
> return 0
> eh:
> declare @.es varchar(512)
> declare @.ed varchar(512)
> exec sp_oageterrorinfo null, @.es OUTPUT, @.ed OUTPUT
> raiserror(@.ed,16,1)
> exec sp_oadestroy @.ts
> exec sp_oadestroy @.fso
> return 1
>
>
> "JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
> news:AFE084C6-4A5F-433D-B693-A3CCEAC70596@.microsoft.com...
>
>|||It should be doable for both types
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:D751008B-0C20-4F1E-A07C-FA6108F2CD08@.microsoft.com...[vbcol=seagreen]
> Thanks for the reply Uri, is this for text file or Excel file (xls, not
> csv)?
>
> "Uri Dimant" wrote:
>
append data to an excel file,
data to an excel file, it seems if it sees that the sheet is available it
creates a new sheet,
I have a logo in my excel file and I want to append the rows below it.JIM
create procedure file_write_text(@.file_name varchar(1000),
@.text varchar(8000),
@.append bit = 0)
as
/*
exec file_write_text 'c:\TEST.XLS','hello'
exec file_write_text 'c:\TEST.XLS',' world',1
*/
declare @.fso int
declare @.ts int
declare @.rv int
exec @.rv = sp_oacreate "scripting.filesystemobject", @.fso OUTPUT, 1
if @.rv <> 0 goto eh
if @.append = 1
begin
--open the text stream for append, will fail if the file doesn't exist
exec @.rv = sp_oamethod @.fso,"opentextfile", @.ts OUTPUT, @.file_name, 8
if @.rv <> 0 goto eh
end
else
begin
--create a new text file, overwriing if necessary
exec @.rv = sp_oamethod @.fso,"createtextfile", @.ts OUTPUT, @.file_name, -1
if @.rv <> 0 goto eh
end
exec @.rv = sp_oamethod @.ts,"write",null ,@.text
if @.rv <> 0 goto eh
exec @.rv = sp_oamethod @.ts,"close"
if @.rv <> 0 goto eh
exec sp_oadestroy @.ts
exec sp_oadestroy @.fso
return 0
eh:
declare @.es varchar(512)
declare @.ed varchar(512)
exec sp_oageterrorinfo null, @.es OUTPUT, @.ed OUTPUT
raiserror(@.ed,16,1)
exec sp_oadestroy @.ts
exec sp_oadestroy @.fso
return 1
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:AFE084C6-4A5F-433D-B693-A3CCEAC70596@.microsoft.com...
>I have a DTS that exports a view to an excel file, is it possible to append
> data to an excel file, it seems if it sees that the sheet is available it
> creates a new sheet,
> I have a logo in my excel file and I want to append the rows below it.
>|||Thanks for the reply Uri, is this for text file or Excel file (xls, not csv)?
"Uri Dimant" wrote:
> JIM
> create procedure file_write_text(@.file_name varchar(1000),
> @.text varchar(8000),
> @.append bit = 0)
> as
> /*
> exec file_write_text 'c:\TEST.XLS','hello'
> exec file_write_text 'c:\TEST.XLS',' world',1
> */
> declare @.fso int
> declare @.ts int
> declare @.rv int
> exec @.rv = sp_oacreate "scripting.filesystemobject", @.fso OUTPUT, 1
> if @.rv <> 0 goto eh
> if @.append = 1
> begin
> --open the text stream for append, will fail if the file doesn't exist
> exec @.rv = sp_oamethod @.fso,"opentextfile", @.ts OUTPUT, @.file_name, 8
> if @.rv <> 0 goto eh
> end
> else
> begin
> --create a new text file, overwriing if necessary
> exec @.rv = sp_oamethod @.fso,"createtextfile", @.ts OUTPUT, @.file_name, -1
> if @.rv <> 0 goto eh
> end
> exec @.rv = sp_oamethod @.ts,"write",null ,@.text
> if @.rv <> 0 goto eh
> exec @.rv = sp_oamethod @.ts,"close"
> if @.rv <> 0 goto eh
> exec sp_oadestroy @.ts
> exec sp_oadestroy @.fso
> return 0
> eh:
> declare @.es varchar(512)
> declare @.ed varchar(512)
> exec sp_oageterrorinfo null, @.es OUTPUT, @.ed OUTPUT
> raiserror(@.ed,16,1)
> exec sp_oadestroy @.ts
> exec sp_oadestroy @.fso
> return 1
>
>
> "JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
> news:AFE084C6-4A5F-433D-B693-A3CCEAC70596@.microsoft.com...
> >I have a DTS that exports a view to an excel file, is it possible to append
> > data to an excel file, it seems if it sees that the sheet is available it
> > creates a new sheet,
> > I have a logo in my excel file and I want to append the rows below it.
> >
>
>|||It should be doable for both types
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:D751008B-0C20-4F1E-A07C-FA6108F2CD08@.microsoft.com...
> Thanks for the reply Uri, is this for text file or Excel file (xls, not
> csv)?
>
> "Uri Dimant" wrote:
>> JIM
>> create procedure file_write_text(@.file_name varchar(1000),
>> @.text varchar(8000),
>> @.append bit = 0)
>> as
>> /*
>> exec file_write_text 'c:\TEST.XLS','hello'
>> exec file_write_text 'c:\TEST.XLS',' world',1
>> */
>> declare @.fso int
>> declare @.ts int
>> declare @.rv int
>> exec @.rv = sp_oacreate "scripting.filesystemobject", @.fso OUTPUT, 1
>> if @.rv <> 0 goto eh
>> if @.append = 1
>> begin
>> --open the text stream for append, will fail if the file doesn't exist
>> exec @.rv = sp_oamethod @.fso,"opentextfile", @.ts OUTPUT, @.file_name, 8
>> if @.rv <> 0 goto eh
>> end
>> else
>> begin
>> --create a new text file, overwriing if necessary
>> exec @.rv = sp_oamethod @.fso,"createtextfile", @.ts OUTPUT,
>> @.file_name, -1
>> if @.rv <> 0 goto eh
>> end
>> exec @.rv = sp_oamethod @.ts,"write",null ,@.text
>> if @.rv <> 0 goto eh
>> exec @.rv = sp_oamethod @.ts,"close"
>> if @.rv <> 0 goto eh
>> exec sp_oadestroy @.ts
>> exec sp_oadestroy @.fso
>> return 0
>> eh:
>> declare @.es varchar(512)
>> declare @.ed varchar(512)
>> exec sp_oageterrorinfo null, @.es OUTPUT, @.ed OUTPUT
>> raiserror(@.ed,16,1)
>> exec sp_oadestroy @.ts
>> exec sp_oadestroy @.fso
>> return 1
>>
>>
>> "JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
>> news:AFE084C6-4A5F-433D-B693-A3CCEAC70596@.microsoft.com...
>> >I have a DTS that exports a view to an excel file, is it possible to
>> >append
>> > data to an excel file, it seems if it sees that the sheet is available
>> > it
>> > creates a new sheet,
>> > I have a logo in my excel file and I want to append the rows below it.
>> >
>>
append data to an excel file
I have a DTS that exports a view to an excel file, is it possible to append data to an excel file, it seems if it sees that the sheet is available it creates a new sheet,
I have a logo in my excel file and I want to append the rows below it.
If you're looking to populate a Worksheet with data at a specific location I think you will probably need to use Excel automation instead of a batch or data access method. See the following for more info:
How to transfer data to an Excel workbook by using Visual Basic .NET
Thursday, February 9, 2012
Anything better than TSQL?
it is a phenomenal data query language. However, in my view, it may be a
little too much so, because with all of its control constructs and additions
to SQL92, it almost gives the appearance of and certainly gives the
opportunity to be used as a general purpose programming language. However, a
s
a programming language, it is not very good at all. Although it is certainly
capable of doing most any general purpose task (and almost certainly turing
complete), it is decades behind any major language today (again, I speak
regarding its consideration as a general purpose programming language).
Now to the question.
Recently, I've been doing a good deal of business logic that, for legacy and
practical reasons is implemented in TSQL.
Is there a way to use a more capable language in perhaps another layer atop
SQL Server while still retaining the local access to all of the database
contents?
Maybe embedded TSQL in C# or vice versa?
I know that such a thing is considered unneccessary, and that
the standard response would probably be 'redesign your database' or
'build some middleware thing', but out of curiosity I have to ask if there
is another option.
Thanks for your input,
KyleSQL Server 2005 does exactly what you want. Too bad it's still in beta.
"Kyle" <Kyle@.discussions.microsoft.com> wrote in message
news:F04F95F9-EFCE-4300-BD3F-8ED1A82D3016@.microsoft.com...
> Recently I've been doing a good amount TSQL programming, and I think
> it is a phenomenal data query language. However, in my view, it may be a
> little too much so, because with all of its control constructs and
additions
> to SQL92, it almost gives the appearance of and certainly gives the
> opportunity to be used as a general purpose programming language. However,
as
> a programming language, it is not very good at all. Although it is
certainly
> capable of doing most any general purpose task (and almost certainly
turing
> complete), it is decades behind any major language today (again, I speak
> regarding its consideration as a general purpose programming language).
> Now to the question.
> Recently, I've been doing a good deal of business logic that, for legacy
and
> practical reasons is implemented in TSQL.
> Is there a way to use a more capable language in perhaps another layer
atop
> SQL Server while still retaining the local access to all of the database
> contents?
> Maybe embedded TSQL in C# or vice versa?
> I know that such a thing is considered unneccessary, and that
> the standard response would probably be 'redesign your database' or
> 'build some middleware thing', but out of curiosity I have to ask if there
> is another option.
> Thanks for your input,
> Kyle|||...but it gives us about a year to get ready... ;)|||T-SQL is a simple one-pass compiler that was not meant for application
development. The original "rule of thumb" was never write a proc over
one page (50 lines) long.
You can embed SQL into any of the ANSI X3J languages, but we also have
the SQL/PSM Standard if you want a language designed to be used with
SQL.|||you can build COM components and use them within TSQL using sp_OACreate whic
h
is maybe what you could look into. You could also create extended stored
procedures written in C, C++ although these run in the same address space as
SQL Server so a crash inside one of these procedures can bring down the
server. This fact alone usually makes my choice simple - create COM objects
in VB and most of the programming world will understand it and because it
will run in a seperate address space to SQL Server - the component won't
bring down the server.
regards,
Mark Baekdal
http://www.dbghost.com
http://www.innovartis.co.uk
+44 (0)208 241 1762
Build, Comparison and Synchronization from Source Control = Database change
management for SQL Server
"Kyle" wrote:
> Recently I've been doing a good amount TSQL programming, and I think
> it is a phenomenal data query language. However, in my view, it may be a
> little too much so, because with all of its control constructs and additio
ns
> to SQL92, it almost gives the appearance of and certainly gives the
> opportunity to be used as a general purpose programming language. However,
as
> a programming language, it is not very good at all. Although it is certain
ly
> capable of doing most any general purpose task (and almost certainly turin
g
> complete), it is decades behind any major language today (again, I speak
> regarding its consideration as a general purpose programming language).
> Now to the question.
> Recently, I've been doing a good deal of business logic that, for legacy a
nd
> practical reasons is implemented in TSQL.
> Is there a way to use a more capable language in perhaps another layer ato
p
> SQL Server while still retaining the local access to all of the database
> contents?
> Maybe embedded TSQL in C# or vice versa?
> I know that such a thing is considered unneccessary, and that
> the standard response would probably be 'redesign your database' or
> 'build some middleware thing', but out of curiosity I have to ask if there
> is another option.
> Thanks for your input,
> Kyle|||I would shy away from using COM components in SQL. My experience using them
is
that they are slow and can cause problems if designed to be free-threaded
instead of single threaded apartment. For now, your best bet is to continue
using T-SQL or...
SQL 2005 will really provide what you want. It will allow for procedures in
C#
(or VB.NET) inside of SQL Server. Microsoft has announced the release of SQL
2005 on November 9th this year.
Thomas
"Kyle" <Kyle@.discussions.microsoft.com> wrote in message
news:F04F95F9-EFCE-4300-BD3F-8ED1A82D3016@.microsoft.com...
> Recently I've been doing a good amount TSQL programming, and I think
> it is a phenomenal data query language. However, in my view, it may be a
> little too much so, because with all of its control constructs and additio
ns
> to SQL92, it almost gives the appearance of and certainly gives the
> opportunity to be used as a general purpose programming language. However,
as
> a programming language, it is not very good at all. Although it is certain
ly
> capable of doing most any general purpose task (and almost certainly turin
g
> complete), it is decades behind any major language today (again, I speak
> regarding its consideration as a general purpose programming language).
> Now to the question.
> Recently, I've been doing a good deal of business logic that, for legacy a
nd
> practical reasons is implemented in TSQL.
> Is there a way to use a more capable language in perhaps another layer ato
p
> SQL Server while still retaining the local access to all of the database
> contents?
> Maybe embedded TSQL in C# or vice versa?
> I know that such a thing is considered unneccessary, and that
> the standard response would probably be 'redesign your database' or
> 'build some middleware thing', but out of curiosity I have to ask if there
> is another option.
> Thanks for your input,
> Kyle|||And in the real world people have to deal the situation at hand - keep it
real - we all want the budget for the next best technology but we need to
deal with the present in a realistic manner. 2005 is still not available
which is useless to people who need to deal with the present production
systems, be helpful not ignorant of the situation at hand. Can the problem
wait? Does the problem need a solution currently available?
Simple questions that ultimately will give you the path you need to follow.
when waiting is the best option it means you have to wait - your business
can wait?
when you need a solution - get it, make it work if it fits and the business
requires the function.
regards,
Mark Baekdal
http://www.dbghost.com
http://www.innovartis.co.uk
+44 (0)208 241 1762
Build, Comparison and Synchronization from Source Control = Database change
management for SQL Server
regards,
Mark Baekdal
http://www.dbghost.com
http://www.innovartis.co.uk
+44 (0)208 241 1762
Build, Comparison and Synchronization from Source Control = Database change
management for SQL Server
"Thomas Coleman" wrote:
> I would shy away from using COM components in SQL. My experience using the
m is
> that they are slow and can cause problems if designed to be free-threaded
> instead of single threaded apartment. For now, your best bet is to continu
e
> using T-SQL or...
> SQL 2005 will really provide what you want. It will allow for procedures i
n C#
> (or VB.NET) inside of SQL Server. Microsoft has announced the release of S
QL
> 2005 on November 9th this year.
>
> Thomas
>
> "Kyle" <Kyle@.discussions.microsoft.com> wrote in message
> news:F04F95F9-EFCE-4300-BD3F-8ED1A82D3016@.microsoft.com...
>
>|||There are other solutions than using a COM component in SQL. For example, yo
u
could call the COM component directly. You could use a Web Service etc.
Further, 2005 IS a viable option given that you can get a Go Live license. B
oth
of those options are better, IMO, than calling a COM component through T-SQL
. I
would put COM components called through T-SQL at the bottom of my list of
choices. There are far better solutions available.
> when you need a solution - get it, make it work if it fits and the busines
s
> requires the function.
That's fine to a point. The problem comes when that "temporary" solution bec
omes
a permanent solution. Correcting problems caused by this scenario can be a f
ar
bigger headache than doing it right the first time.
Thomas
"mark baekdal" <markbaekdal@.discussions.microsoft.com> wrote in message
news:0572C462-09E9-48D1-A4BB-A19D9BCA3599@.microsoft.com...
> And in the real world people have to deal the situation at hand - keep it
> real - we all want the budget for the next best technology but we need to
> deal with the present in a realistic manner. 2005 is still not available
> which is useless to people who need to deal with the present production
> systems, be helpful not ignorant of the situation at hand. Can the problem
> wait? Does the problem need a solution currently available?
> Simple questions that ultimately will give you the path you need to follow
.
> when waiting is the best option it means you have to wait - your business
> can wait?
> when you need a solution - get it, make it work if it fits and the busines
s
> requires the function.
>
> regards,
> Mark Baekdal
> http://www.dbghost.com
> http://www.innovartis.co.uk
> +44 (0)208 241 1762
> Build, Comparison and Synchronization from Source Control = Database chang
e
> management for SQL Server