VIEWs - Can It Know Wether A SELECT, UPDATE, Etc Is Executing On It
Apr 6, 2000
VIEW behaviour depending on what operation is run on it.
VIEW syntax is CREATE VIEW xx AS SELECT ... It would be very convinient to know wether a select, update, insert or delete is the operation executed on it so the view could take action accordingly, ie
CREATE VIEW xxx AS SELECT ..
CASE UPDATE THEN do_this
CASE SELECT THEN do_that etc.
Does anyone know if this is possible?
View 2 Replies
ADVERTISEMENT
Mar 1, 2006
Hi,I am new to using SQL. I want to be able to exucute a query that Iplace in a view. I want this views to be executed every time a valuechange in one of the table in a particular field. So my guess was touse a trigger that will call the views every time the data change inthe selected table. Is this the proper way of doing thing? Should Iuse other SQL tools to achive this. I search for exemple of triggerexecuting views but did not found anything as of yet. Let's use thisdummy name for the exemple:Database: DB1Table: Tbl1Special field in Tbl1: flagViews name: views_01Thank you.Philippe
View 7 Replies
View Related
Jan 31, 2006
Hello,
can someone tell me where I can look to find a sql command that
is being executed by an application against my database?
In Oracle, I look in the v$sql_text view - is there something
similar in SQL Server 2000 ?
Many thanks in advance
View 2 Replies
View Related
Jan 20, 2007
Dear ppl,
In Merge Replication SQL Server2005, what is the easiest way of finding out wether a row on the publisher database has ever been replicated to subscribers?
Regards
View 3 Replies
View Related
Mar 19, 2015
I have created a trigger on a table that get's too many updates so to analyze what records and what columns get updates I have coded a trigger that inserts into a table the record key and a flag on each column to let me know what is updates. Now that I am presenting the data to the developers I have been asked to provide the update / insert or delete statement
So on my trigger I have tried using dynamic management views but its returning the actual trigger code not the parent SQL Script that triggered it.
This is what I am using.
select@dDate as dDate, dest.[dbid], dest.[objectid], dest.[number], dest.[encrypted],
case when sder.[statement_start_offset] > 0 --the start of the active command is not at the beginning of the full command text
thencasesder.[statement_end_offset]
[Code] .....
View 2 Replies
View Related
Dec 7, 2004
Hi:
Currently I have two tables T1 and T2. A view V1 is defined over T1 with an INSTEAD OF UPDATE trigger and another view V2 is defined over V1 and T2 with another INSTEAD OF UPDATE trigger. Unfortunately, inside V2’s trigger following update statement is not working:
Update V1 set V1.name = i.name from inserted i
because SQL server complains:
View 'V1' has an INSTEAD OF UPDATE trigger and cannot be a target of an UPDATE FROM statement.
Is there any way to get around this problem? I.e., how can I make the INSTEAD OF UPDATE trigger in V2 to work if I can’t reference “inserted”?
Your help is appreciated,
Jeff
View 1 Replies
View Related
Jul 5, 2001
Hello All!!
Below is a part of my code. I need to find out if I could execute the below statement.
select @string_sortorder = 'select max(sortorder) from geo_lineobj where pipeid = ' + str(@geo_pipeid)
select @string_sortorder
exec @string_sortorder @max_sortorder
When I select the @max_sortorder the value I'm getting is a null. The sortorder is an int datatype and the @geo_pipeid is also an int datatype.
I need to to get the @max_sortorder to continue my coding. Does anyone know why I'm getting a null @max_sortorder?
Any suggestion would be of great help.
Thank you
View 2 Replies
View Related
Apr 15, 2006
People are telling me it is bad to putselect * from <atable>in a view. I better should list all fields of the table inside thedefinition of the view.I dont know exactly why but some say:A select * from makes sql server does a table scan.Is that true, even if i put a where on the select on the view? And what if idont list all fields in the select on the view?Thanks for the answer.Peter
View 33 Replies
View Related
Aug 16, 2007
Hi All,
Iam having 2 tables say Emp table and Department Table. Iam having a view which joins 2 tables.
example
select *,Department.DeptStatus, Department.DepartmentName from Employee INNER JOIN Department ON Department.deptno=Employee.DeptNO.
When I add a new column to the Employee table say EmployeeStatus then my view get corrupted.what i mean is that the last newly added column from emloyee table takes the Name as DeptStatus and shows values of the EmployeeStatus Column. We have been creating new Columns in SQL 2000 we never faced this issue but iam seeing this issue only in SQL Server 2005.
Thanks in Advance.
cheers,
Sada
View 7 Replies
View Related
Aug 2, 2007
Hai, I'm an novice in Sql Server. I wanna know why we are going for VIEWS instead of SELECT statement in Sql Server 2005. However, both are going to perform the same task (i.e, Retreiving data) from the database.
View 5 Replies
View Related
Sep 19, 2007
I am attempting to use views and Instead of triggers to insert, update and delete rows from THE table that is exposed through a view. In my application, the views provide a filtered set of rows from the base table that a user has permission to access. To improve performance, I submit a set (i.e. multiple rows) to be acted upon in a single SQL Statement. The insert and delete triggers work great. But, for some reason, the Instead of Update trigger on the view will not accept multiple rows. The Error I receive is:
Msg 414, Level 16, State 1, Line 1
UPDATE is not allowed because the statement updates view "FooView" which participates in a join and has an INSTEAD OF UPDATE trigger.
The only hint I can find about this behavior is from BOL for the Transact-SQL Update statement:
"A view with an INSTEAD OF UPDATE trigger cannot be a target of an UPDATE with a FROM clause."
Why is this not allowed?
If the trigger is on a table and the update statement is executed against the table it works. Why is the statement not allowed to execute against a view that has exactly the same construction as the table?
Any help or explanations for this behavior is appreciated.
I've included a code sample that will replicate the behavior and problem.
----------------------------------------------
Code Sample:
CREATE TABLE Foo (
ID INT PRIMARY KEY,
aName VARCHAR (10),
aValue FLOAT
)
GO
-- The view and its triggers
CREATE VIEW FooView AS
SELECT [ID]
,[aName]
,[aValue]
FROM Foo
GO
-- Instead of Triggers on the view
CREATE TRIGGER FooViewInsertInsteadOf
ON FooView
INSTEAD OF INSERT
AS
BEGIN
INSERT INTO Foo
SELECT Id, aName, aValue
FROM INSERTED
END
GO
CREATE TRIGGER FooViewInsteadOfUpdate
ON FooView
INSTEAD OF UPDATE
AS
BEGIN
UPDATE Foo
SET
Foo.aName = Inserted.aName,
Foo.aValue = Inserted.aValue
FROM Foo
JOIN INSERTED on INSERTED.ID = Foo.Id
END
GO
-- Test the Insert Trigger
INSERT INTO FooView
SELECT 2, 'First', 2.0
UNION ALL
SELECT 3, 'First', 3.0
UNION ALL
SELECT 4, 'First', 4.0
GO
SELECT * FROM FooView
GO
-- Update a single row in the view. This works with the Instead of Update Trigger.
UPDATE FooView
SET
FooView.aName = 'Third',
FooView.aValue = 3.3
WHERE FooView.ID = 3
GO
SELECT * FROM FooView
GO
===============================
-- T-SQL will not support the following statement when executed against a view with an instead of trigger.
-- If this statement is executed against a table with an instead of trigger it works as desired.
-- Why can't I execute this against the view?
UPDATE FooView
SET
FooView.aName = tmp.f1,
FooView.aValue = tmp.f2
FROM FooView
JOIN (
SELECT 2 as [id], 'Second' as [F1], 2.2 as [F2]
UNION ALL
SELECT 4, 'Fourth', 4.33
)
as tmp on FooView.ID = tmp.[id]
View 4 Replies
View Related
May 16, 2006
I have multiple SqlDataSources on a page. I only want them to execute the select query when the user performs a certain action. Is this possible? Or do they all execute as soon as the page is loaded?
View 1 Replies
View Related
Jun 12, 2008
i wanna execute a stored procedure in a select and use its return type
i.e
select name from table1 where id = sp 1,1
i executed it and occurred an error
help me pls
View 2 Replies
View Related
Dec 4, 2007
Hello,
How do , I grant select privileges on all the Views of the database to a user in SQl 2005. All the tables and views in the database are under the dbo schema.
Thanks.
View 1 Replies
View Related
Sep 9, 2007
Is it better to use just a SELECT statement or a view when working with a small database? Does anyone know which would perform better?
............................................................thanks
View 12 Replies
View Related
Aug 30, 2000
My client want me to update a table and the view with a new column which should be hidden. I am kind of confused on how to go about this in order to get a good result. PLEASE HELP!!
View 1 Replies
View Related
Aug 27, 2001
hI
DOES ANY BODY KNOW HOW TO EXECUTE STORE PROCEDURE IN SELECT STATMENT
THANKS
jk
View 1 Replies
View Related
Sep 29, 2007
Hi,
i have problem executing the dynamic query.
I have straight forward query as below and works fine
declare @count bigint
declare @varcount varchar(max)
set @varcount ='5'
If convert(bigint, @varcount) <> 4
print ' not 4 '
else
print 'Its 4'
Here is my dynamic query. The number of records (@No ) and the table name ( @table ) will be available for me as parameters to my stoped proc
declare @count bigint
declare @varcount varchar(max)
declare @tempTable varchar(max)
declare @vsSql varchar(max)
declare @No bigint
set @No = 5
set @table = 'sam'
set @varcount = ''
select @vsSql = 'declare @varcount varchar(max); select @varcount = count(*) from ' + @table + '; If convert(bigint,@varcount) <> ' + @No + ' raiserror(' +'mismatch, 11,1' +')'
When executed it throws the follwing error
Msg 8114, Level 16, State 5, Line 10
Error converting data type varchar to bigint.
Can anyone point out what to change in the query to work
~mohan
View 1 Replies
View Related
Jul 9, 2006
Hi,
I want to be able to select data from a database without using grid
view etc. I can set up a connection and bind it to a grid view but I
would like to do some data processing without showing it. Something like
select id from table where name = "x"
store id in idvar
store the row count to a variable rowcount
if rowcount > 0
select name from table2 where id = idvar
endif
etc
I can see how to set the sqldatasource select command but not how to run it and get results out of it. Please help
View 1 Replies
View Related
Nov 10, 2006
Hi
I have a problem executing a SELECT inside a TRAN against other computer
For example:
IN THE SQL Query Analizer of the COMPUTER2
1) this runs OK
BEGIN TRAN
SELECT * FROM COMPUTER2.DATABASE.DBO.TABLE
COMMIT TRAN
2) this runs OK
SELECT * FROM COMPUTER2.DATABASE.DBO.TABLE
3) this runs OK
SELECT * FROM COMPUTER1.DATABASE.DBO.TABLE
4) this runs bad
BEGIN TRAN
SELECT * FROM COMPUTER1.DATABASE.DBO.TABLE
COMMIT TRAN
The problem is that TABLE locks and it does not finish.
I've been looking for similar ERRORS in Microsoft Support but I found nothing
I've uninstall and install de SQL server 2000 SP4 and the problems continues the same
Please, someone could help me, thanks
View 11 Replies
View Related
Mar 5, 2006
I've had a couple problems with SMO and I wonder if anyone else has. Specifically, when I run through stored procedures (just like your example) it is painfully slow. Maybe 5 a second. Another problem is filtering on nonsystem objects with either "SVR.SetDefaultInitFields(typeof(Microsoft.SqlServer.Management.Smo.View), "IsSystemObject"); or View.isSystemObject.
Both cases crash my app. Any ideas?
Below are two ways that both crash or hang.
SVR.SetDefaultInitFields(typeof(Microsoft.SqlServer.Management.Smo.View), "IsSystemObject");
foreach (Microsoft.SqlServer.Management.Smo.View view in viewCollection)
{}
OR
foreach (Microsoft.SqlServer.Management.Smo.View view in viewCollection)
{
if (!view.IsSystemObject)
{}
}
View 1 Replies
View Related
Mar 17, 2008
If I have a view such as: SELECT T.* FROM T
When I add a column to table T the view is not updated to reflect that change.
Furthermore, if there are other columns after the * in the view (for example SELECT T.*, GETDATE() as "My Date" FROM T) the last columns will contain incorrect data.
Is there a work around for this? An "auto-recompile when tables are modified" kind of option?
Thanks
Nick
PS: This is the script I used for testing:
create table tt (
test1 int primary key,
test2 int)
go
insert into tt (test1, test2) values (1,2)
go
create view vw_tt as select *, getdate() as "My Date" from tt
go
select * from vw_tt
go
create view vw_tt2 as select * from tt
go
alter table tt add test3 int
go
select * from vw_tt
select * from vw_tt2
select * from tt
drop table tt
drop view vw_tt
drop view vw_tt2
View 9 Replies
View Related
Dec 14, 2011
grant SELECTÂ Â on all_columns to yogi_bear;
grant SELECT  on all_objects to yogi_bear;
grant SELECT  on all_views   to yogi_bear;
Â
but it doesn't work, why? I know how to do it with a cursor or dynamic sql, but why won't these sql statements work?
View 7 Replies
View Related
Feb 1, 2007
I am building a dashboard features that allows user to select reports from a dropdownlist. It is pulling from a table called Reports (cols: ReportID, Description, sqlView) In this Report table the report is associated to a view that queries the report.
And the user's selections are stored in table called UserReport (cols: userID, ReportID, createDt) .
I need to get a Dataset to contain datables of all reports selected. (for example a user select 3 reports, the dataset should contain 3 datables that represent the report).
I want to accomplish this by create a store procedure that queries the Reports table and then dynamically executes the views that related to the user selected reports. Can anyone give me an example on how to create the storeprocedure?
Thanks,
CG
View 3 Replies
View Related
Sep 24, 2013
I'm trying to grant a user group select access to all the views in a database. I already made a query which creates a result set whit the SQL Syntax I (displayed below) need but it seems to be impossible to get this result set executed after creation.
use [AdventureWorksDW2008R2]
SELECT
'GRANT SELECT ON [' + SCHEMA_NAME(Schema_id) + '].[' + name + '] TO [DOMAINGROUP]'
FROM sys.views;
View 5 Replies
View Related
Jul 20, 2005
Hi all,We have an application through which we are bulk inserting rows into aview. The definition of the view is such that it selects columns froma table on a remote server. I have added the servers usingsp_addlinkedserver on both database servers.When I call the Commit API of oledb I get the following error:Error state: 1, Severity: 19, Server: TST-PROC22, Line#: 1, msg:SqlDumpExceptionHandler: Process 66 generated fatal exception c0000005EXCEPTION_ACCESS_VIOLATION. SQL Server is terminating this process.I would like to know if we can bulk insert rows into a view thataccesses a table on the remote server using the "bulk insert" or bcpcommand. I tried a small test through SQL Query Analyser to use "bulkinsert" on a such a view.The test that I performed was the following:On database server 1 :create table iqbal (var1 int, var2 int)On database server 2 (remote server):create view iqbal as select var1,var2 from[DBServer1].[SomeDB].[dbo].[iqbal]set xact_abort onbulk insert iqbal from '\MachineIqbaliqbaldata.txt'The bulk insert operation failed with the following error message:[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionCheckForData(CheckforData()).Server: Msg 11, Level 16, State 1, Line 0General network error. Check your network documentation.Connection BrokenThe file iqbaldata.txt contents were :112233If the table that the view references is on the same server then weare able to bulk insert successfully.Is there a way by which I should be able to bulk insert rows into aview that selects from a table on a remote server. If not then couldanyone suggest a workaround. I would actually like to know someworkaround to get the code working using OLEDB. Due to unavoidablereasons I cannot output the records to the file and then use bcp tobulk insert the records in the remote table. I need to have some wayof doing it using OLEDB.Thanks in advanceIqbal
View 7 Replies
View Related
Apr 3, 2006
Fellow database developers,I would like to draw on your experience with views. I have a databasethat includes many views. Sometimes, views contains other views, andthose views in turn may contain views. In fact, I have some views inmy database that are a product of nested views of up to 6 levels deep!The reason we did this was.1. Object-oriented in nature. Makes it easy to work with them.2. Changing an underlying view (adding new fields, removing etc),automatically the higher up views inherit this new information. Thismake maintenance very easy.3. These nested views are only ever used for the reporting side of ourapplication, not for the day-to-day database use by the application.We use Crystal Reports and Crystal is smart enough (can't believe Ijust said that about Crystal) to only pull back the fields that arebeing accessed by the report. In other words, Crystal will issue aSelect field1, field2, field3 from ReportingView Where .... eventhough "ReportingView" contains a long list of fields.Problems I can see.1. Parent views generally use "Select * From childview". This meansthat we have to execute a "sp_refreshview" command against all viewswhenever child views are altered.2. Parent views return a lot of information that isn't necessarilyused.3. Makes it harder to track down exactly where the information iscoming from. You have to drill right through to the child view to seethe raw table joins etc.Does anyone have any comments on this database design? I would love tohear your opinions and tales from the trenches.Best regards,Rod.
View 15 Replies
View Related
Jan 24, 2008
Hi,
I have a web application using Stored Procedure (SP). I see that there's a SP taking long time to execute. I try to capture it by Profiler Tool, and find out that with the same SP on the same db with the same parameter. The duration of executing by my web app is far bigger than the duration of executing on SQl server management studio - query window
Please see the image through this url http://kyxao.net/127/ExecutionProblem.png
Any ideas for this issue?
Thanks a lot
View 1 Replies
View Related
Jan 23, 2008
Hi,I have a web application using Stored Procedure (SP). I see that there's a SP taking long time to execute. I try to capture it by Profiler Tool, and find out that with the same SP on the same db with the same parameter. The duration of executing by my web app is far bigger than the duration of executing on SQl server management studio - query windowPlease see the image attached http://kyxao.net/127/ExecutionProblem.png Any ideas for this issue?Thanks a lot Jalijack
View 2 Replies
View Related
Oct 10, 2006
Hi all,I am facing an unusual issue here. I have a stored procedure, that return different set of result when I execute it from .NET component compare to when I execute it from SQL Management Studio. But as soon as I recompile the stored procedure, both will return the same results.This started to really annoying me, any thoughts or solution? Thanks very much guys
View 2 Replies
View Related
Sep 6, 2007
Which is more efficient? One large view that joins >=10 tables, or a few smaller views that join only the tables needed for individual pages?
View 1 Replies
View Related
Jun 28, 2007
Hello.
Newbie here. I've only been using SQL for about a year now and have some minor questions about sql objects that reference other objects.
We have some views which reference other views in the joins. I will call one the primary view and the one being referenced in the joins as the secondary view.
Recently we made changes to the secondary view.
After which the primary views which referenced it would not work because of this change and had to be 'refreshed' by using drop/create scripts which essentially just dropped it and recreated the exact same view. I do not recall the exact error message that was returned other than it seemed to suggest that it could no longer see the secondary view since it had been changed. Nothing in the primary view was changed in any way, just the secondary.
Some here where I work have suggested off hand that this was a recompile of the primary view because the contents of the secondary changed.
My questions are:
1. Exactly why did this happen and is there a proper name for it when it does?
2. The same problem does not seem to occur when we have stored procedures referencing views in the joins which had just been changed. Why is that?
Thanks for any help on the matter. I greatly appreciate it.
View 3 Replies
View Related
Apr 24, 2007
Hello everyone,
I have the following sql query which basically gives me 10 ramdon records in a table, what i want to do is update those records selected. i.e update the select query.I want to upddate a field in the 10 records returned by the query below. Thank you.
SELECT TOP (10) *FROM tblSiebelActivity1000WHERE (DATEPART(mm, dteActivityDueRT) = MONTH(GETDATE())) AND (DATEPART(dd, dteActivityDueRT) = DAY(GETDATE())) AND (txtServiceRegion = 'nj02')ORDER BY NEWID(), txtActivityNumber
View 6 Replies
View Related