Showing posts with label version. Show all posts
Showing posts with label version. Show all posts

Monday, March 19, 2012

Deleting a record from a VIEW

Hi All,
I am using Microsoft SQL Enterprise Manager version 8.0 and have
created a view from a combination of 4 different tables. I would like
to be able to go into sql and open the view and select a row and
delete that row however this seem impossible right now. I am not sure
if it's possible to delete a row from a view?? Or could it be that
these tables are all interconnected and in order to delete a record
that is joined to one or more of the tables it has to be deleted at
the top level of the join heirarchy etc etc. (do you understand what i
mean?) Can this be done??
Thanks in advance,
ErinXmlAdoNewbie (erin.sebastian@.cowaninsurancegroup.com) writes:
> I am using Microsoft SQL Enterprise Manager version 8.0 and have
> created a view from a combination of 4 different tables. I would like
> to be able to go into sql and open the view and select a row and
> delete that row however this seem impossible right now. I am not sure
> if it's possible to delete a row from a view?? Or could it be that
> these tables are all interconnected and in order to delete a record
> that is joined to one or more of the tables it has to be deleted at
> the top level of the join heirarchy etc etc. (do you understand what i
> mean?) Can this be done??

So if you have a view which is like:

create view petra (a1, b1, b2, c) as
SELECT n.a, n.b, k.b, c
from nisse n join kalle k on n.a = k.a
go

And you say "DELETE petra WHERE a1 = 2" what do you expect to happen?
From which table is the row to be deleted?

Anyway, Books Online says in the topic for DELETE:

view_name

Is the name of a view. The view referenced by view_name must be
updatable and reference exactly one base table in the FROM clause of
the view. For more information about updatable views, see CREATE VIEW.

Thus, it does not seem from your description that your view would
be updatable.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||On 7 Jun 2004 11:39:38 -0700, XmlAdoNewbie wrote:

> Hi All,
> I am using Microsoft SQL Enterprise Manager version 8.0 and have
> created a view from a combination of 4 different tables. I would like
> to be able to go into sql and open the view and select a row and
> delete that row however this seem impossible right now. I am not sure
> if it's possible to delete a row from a view?? Or could it be that
> these tables are all interconnected and in order to delete a record
> that is joined to one or more of the tables it has to be deleted at
> the top level of the join heirarchy etc etc. (do you understand what i
> mean?) Can this be done??
> Thanks in advance,
> Erin

As Mr. Sommarskog explained, it is not technically possible to delete from
a view based on more than one table, and the reason is that it is unclear
what record should actually be deleted. However, if it is clear to you,
then you can do something like the following.

CREATE TABLE1 ( KEY1 int PRIMARY KEY,
NAME varchar(30) NOT NULL,
KEY2 int NOT NULL,
KEY3 int NOT NULL,
KEY4 int NOT NULL);
CREATE TABLE2 ( KEY2 int PRIMARY KEY, CITY varchar(30) NOT NULL);
CREATE TABLE3 ( KEY3 int PRIMARY KEY, STATE varchar(2) NOT NULL);
CREATE TABLE4 ( KEY4 int PRIMARY KEY, MARKET varchar(30) NOT NULL);

CREATE VIEW1 AS
SELECT TABLE1.KEY1, TABLE1.NAME, TABLE2.CITY, TABLE3.STATE, TABLE4.MARKET
FROM TABLE1
INNER JOIN TABLE2 on TABLE1.KEY2 = TABLE2.KEY2
INNER JOIN TABLE3 on TABLE1.KEY3 = TABLE2.KEY3
INNER JOIN TABLE4 on TABLE1.KEY4 = TABLE2.KEY4;

Now, suppose what you want to do is delete all rows from TABLE1 that match
TABLE4.MARKET='Orlando':

DELETE FROM TABLE1
WHERE TABLE1.KEY1 IN (
SELECT VIEW1.KEY1 FROM VIEW1 WHERE VIEW1.MARKET = 'Orlando' );

So, you see that you're not deleting directly from the view; you're
deleting from a table that participates in the view, based on information
you retrieved from the view.|||You can also define an INSTEAD OF TRIGGER on the view and delete the
records from the two tables in the trigger definition. This is
probably the cleanest way to do it and gives you the perception of
being able to delete from the view.

Ross Presser <rpresser@.imtek.com> wrote in message news:<143lxsb87s5gp.1l5wdsmlcexee$.dlg@.40tude.net>...
> On 7 Jun 2004 11:39:38 -0700, XmlAdoNewbie wrote:
> > Hi All,
> > I am using Microsoft SQL Enterprise Manager version 8.0 and have
> > created a view from a combination of 4 different tables. I would like
> > to be able to go into sql and open the view and select a row and
> > delete that row however this seem impossible right now. I am not sure
> > if it's possible to delete a row from a view?? Or could it be that
> > these tables are all interconnected and in order to delete a record
> > that is joined to one or more of the tables it has to be deleted at
> > the top level of the join heirarchy etc etc. (do you understand what i
> > mean?) Can this be done??
> > Thanks in advance,
> > Erin
> As Mr. Sommarskog explained, it is not technically possible to delete from
> a view based on more than one table, and the reason is that it is unclear
> what record should actually be deleted. However, if it is clear to you,
> then you can do something like the following.
> CREATE TABLE1 ( KEY1 int PRIMARY KEY,
> NAME varchar(30) NOT NULL,
> KEY2 int NOT NULL,
> KEY3 int NOT NULL,
> KEY4 int NOT NULL);
> CREATE TABLE2 ( KEY2 int PRIMARY KEY, CITY varchar(30) NOT NULL);
> CREATE TABLE3 ( KEY3 int PRIMARY KEY, STATE varchar(2) NOT NULL);
> CREATE TABLE4 ( KEY4 int PRIMARY KEY, MARKET varchar(30) NOT NULL);
> CREATE VIEW1 AS
> SELECT TABLE1.KEY1, TABLE1.NAME, TABLE2.CITY, TABLE3.STATE, TABLE4.MARKET
> FROM TABLE1
> INNER JOIN TABLE2 on TABLE1.KEY2 = TABLE2.KEY2
> INNER JOIN TABLE3 on TABLE1.KEY3 = TABLE2.KEY3
> INNER JOIN TABLE4 on TABLE1.KEY4 = TABLE2.KEY4;
> Now, suppose what you want to do is delete all rows from TABLE1 that match
> TABLE4.MARKET='Orlando':
> DELETE FROM TABLE1
> WHERE TABLE1.KEY1 IN (
> SELECT VIEW1.KEY1 FROM VIEW1 WHERE VIEW1.MARKET = 'Orlando' );
> So, you see that you're not deleting directly from the view; you're
> deleting from a table that participates in the view, based on information
> you retrieved from the view.|||Thanks Everyone for your help! I have decided to build a little
utility in C# that will allow the user to pick the record to delete
from the view and then delete the record from the table and all joined
tables.
I appreciate all your help!
Erin

Friday, March 9, 2012

Deleted row information cannot be accessed through the row

Hi,
I got following exception when accessing database using release version of
my C# application:
System.Data.DeletedRowInaccessibleException: Deleted row information cannot
be accessed through the row.
at System.Data.DataRow.GetDefaultRecord()
at System.Data.DataRow.get_Item(String columnName)
at ZCAP.Database.ZappUser.get_ZappRole() in C:\ZCAP\ZCAP
Database\TwsUser.cs:line 185
at ZCAP.ZAPP.Tws.tabPageAccounting_Layout(Object sender, LayoutEventArgs
e) in C:\ZCAP\TWS\Tws.cs:line 2068
at System.Windows.Forms.Control.OnLayout(LayoutEventA rgs levent)
at System.Windows.Forms.ScrollableControl.OnLayout(La youtEventArgs
levent)
at System.Windows.Forms.Control.PerformLayout(LayoutE ventArgs args)
at System.Windows.Forms.Control.PerformLayout()
at ZCAP.ZAPP.Tws.InitializeComponent() in
C:\ZCAP\TWS\Tws.designer.cs:line 4025
at ZCAP.ZAPP.Tws..ctor(ZappUser user) in C:\ZCAP\TWS\Tws.cs:line 33
at ZCAP.ZAPP.TwsMain.Main() in C:\ZCAP\TWS\TwsMain.cs:line 38
In following 2 situations, there is no exception:
(1) Running under debug version
(2) In visual studio, if I select "Release", then click "Debug" -> "Start
Debugging"
Your help is highly appreciated!
Hank
"Hang" <hyuan@.zcap.net> wrote in message
news:#LcxwJBaHHA.4948@.TK2MSFTNGP05.phx.gbl...
> Hi,
> I got following exception when accessing database using release version of
> my C# application:
> System.Data.DeletedRowInaccessibleException: Deleted row information
> cannot be accessed through the row.
> at System.Data.DataRow.GetDefaultRecord()
> at System.Data.DataRow.get_Item(String columnName)
> at ZCAP.Database.ZappUser.get_ZappRole() in C:\ZCAP\ZCAP
> Database\TwsUser.cs:line 185
> at ZCAP.ZAPP.Tws.tabPageAccounting_Layout(Object sender, LayoutEventArgs
> e) in C:\ZCAP\TWS\Tws.cs:line 2068
> at System.Windows.Forms.Control.OnLayout(LayoutEventA rgs levent)
> at System.Windows.Forms.ScrollableControl.OnLayout(La youtEventArgs
> levent)
> at System.Windows.Forms.Control.PerformLayout(LayoutE ventArgs args)
> at System.Windows.Forms.Control.PerformLayout()
> at ZCAP.ZAPP.Tws.InitializeComponent() in
> C:\ZCAP\TWS\Tws.designer.cs:line 4025
> at ZCAP.ZAPP.Tws..ctor(ZappUser user) in C:\ZCAP\TWS\Tws.cs:line 33
> at ZCAP.ZAPP.TwsMain.Main() in C:\ZCAP\TWS\TwsMain.cs:line 38
> In following 2 situations, there is no exception:
> (1) Running under debug version
> (2) In visual studio, if I select "Release", then click "Debug" -> "Start
> Debugging"
>
This is an ADO.NET question, not a SQL Server question. Try posting in the
ADO.NET groups.
David

Deleted row information cannot be accessed through the row

Hi,
I got following exception when accessing database using release version of
my C# application:
System.Data.DeletedRowInaccessibleException: Deleted row information cannot
be accessed through the row.
at System.Data.DataRow.GetDefaultRecord()
at System.Data.DataRow.get_Item(String columnName)
at ZCAP.Database.ZappUser.get_ZappRole() in C:\ZCAP\ZCAP
Database\TwsUser.cs:line 185
at ZCAP.ZAPP.Tws.tabPageAccounting_Layout(Object sender, LayoutEventArgs
e) in C:\ZCAP\TWS\Tws.cs:line 2068
at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
at System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs
levent)
at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
at System.Windows.Forms.Control.PerformLayout()
at ZCAP.ZAPP.Tws.InitializeComponent() in
C:\ZCAP\TWS\Tws.designer.cs:line 4025
at ZCAP.ZAPP.Tws..ctor(ZappUser user) in C:\ZCAP\TWS\Tws.cs:line 33
at ZCAP.ZAPP.TwsMain.Main() in C:\ZCAP\TWS\TwsMain.cs:line 38
In following 2 situations, there is no exception:
(1) Running under debug version
(2) In visual studio, if I select "Release", then click "Debug" -> "Start
Debugging"
Your help is highly appreciated!
Hank"Hang" <hyuan@.zcap.net> wrote in message
news:#LcxwJBaHHA.4948@.TK2MSFTNGP05.phx.gbl...
> Hi,
> I got following exception when accessing database using release version of
> my C# application:
> System.Data.DeletedRowInaccessibleException: Deleted row information
> cannot be accessed through the row.
> at System.Data.DataRow.GetDefaultRecord()
> at System.Data.DataRow.get_Item(String columnName)
> at ZCAP.Database.ZappUser.get_ZappRole() in C:\ZCAP\ZCAP
> Database\TwsUser.cs:line 185
> at ZCAP.ZAPP.Tws.tabPageAccounting_Layout(Object sender, LayoutEventArgs
> e) in C:\ZCAP\TWS\Tws.cs:line 2068
> at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
> at System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs
> levent)
> at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
> at System.Windows.Forms.Control.PerformLayout()
> at ZCAP.ZAPP.Tws.InitializeComponent() in
> C:\ZCAP\TWS\Tws.designer.cs:line 4025
> at ZCAP.ZAPP.Tws..ctor(ZappUser user) in C:\ZCAP\TWS\Tws.cs:line 33
> at ZCAP.ZAPP.TwsMain.Main() in C:\ZCAP\TWS\TwsMain.cs:line 38
> In following 2 situations, there is no exception:
> (1) Running under debug version
> (2) In visual studio, if I select "Release", then click "Debug" -> "Start
> Debugging"
>
This is an ADO.NET question, not a SQL Server question. Try posting in the
ADO.NET groups.
David

Deleted row information cannot be accessed through the row

Hi,
I got following exception when accessing database using release version of
my C# application:
System.Data.DeletedRowInaccessibleException: Deleted row information cannot
be accessed through the row.
at System.Data.DataRow.GetDefaultRecord()
at System.Data.DataRow.get_Item(String columnName)
at ZCAP.Database.ZappUser.get_ZappRole() in C:\ZCAP\ZCAP
Database\TwsUser.cs:line 185
at ZCAP.ZAPP.Tws.tabPageAccounting_Layout(Object sender, LayoutEventArgs
e) in C:\ZCAP\TWS\Tws.cs:line 2068
at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
at System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs
levent)
at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
at System.Windows.Forms.Control.PerformLayout()
at ZCAP.ZAPP.Tws.InitializeComponent() in
C:\ZCAP\TWS\Tws.designer.cs:line 4025
at ZCAP.ZAPP.Tws..ctor(ZappUser user) in C:\ZCAP\TWS\Tws.cs:line 33
at ZCAP.ZAPP.TwsMain.Main() in C:\ZCAP\TWS\TwsMain.cs:line 38
In following 2 situations, there is no exception:
(1) Running under debug version
(2) In visual studio, if I select "Release", then click "Debug" -> "Start
Debugging"
Your help is highly appreciated!
Hank"Hang" <hyuan@.zcap.net> wrote in message
news:#LcxwJBaHHA.4948@.TK2MSFTNGP05.phx.gbl...
> Hi,
> I got following exception when accessing database using release version of
> my C# application:
> System.Data.DeletedRowInaccessibleException: Deleted row information
> cannot be accessed through the row.
> at System.Data.DataRow.GetDefaultRecord()
> at System.Data.DataRow.get_Item(String columnName)
> at ZCAP.Database.ZappUser.get_ZappRole() in C:\ZCAP\ZCAP
> Database\TwsUser.cs:line 185
> at ZCAP.ZAPP.Tws.tabPageAccounting_Layout(Object sender, LayoutEventArgs
> e) in C:\ZCAP\TWS\Tws.cs:line 2068
> at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
> at System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs
> levent)
> at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
> at System.Windows.Forms.Control.PerformLayout()
> at ZCAP.ZAPP.Tws.InitializeComponent() in
> C:\ZCAP\TWS\Tws.designer.cs:line 4025
> at ZCAP.ZAPP.Tws..ctor(ZappUser user) in C:\ZCAP\TWS\Tws.cs:line 33
> at ZCAP.ZAPP.TwsMain.Main() in C:\ZCAP\TWS\TwsMain.cs:line 38
> In following 2 situations, there is no exception:
> (1) Running under debug version
> (2) In visual studio, if I select "Release", then click "Debug" -> "Start
> Debugging"
>
This is an ADO.NET question, not a SQL Server question. Try posting in the
ADO.NET groups.
David

Friday, February 24, 2012

delete sql not working.

hi

win 2k and xp
excel 2k
sqlserver version 7
the code below execute but when i query the table, the data is still in there. can anyone help?

Sub UPDATED_DELETE()

Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
dim MyDate As Date

MyDate = Format(Date, "MM/DD/YYYY")

Set conn = New ADODB.Connection
Set cmd = New ADODB.Command

conn.ConnectionString = "ODBC=SQL Server;DSN=LOGCALL_TABLE;UID=richard;APP=Microsoft Query;WSID=RICHARD;Trusted_Connection=Yes"
conn.ConnectionTimeout = 30
conn.Open

Set cmd.ActiveConnection = conn

cmd.CommandText = "DELETE FROM LOGCALL_TABLE WHERE LOGCALL_TABLE.OpenCall like 'X' AND LOGCALL_TABLE.StopTime like '" & Format(Range("I" & CStr(ActiveCell.Row)).Value, "HH:MM:SS") & "' AND LOGCALL_TABLE.EndTime like '" & Format(Range("J" & CStr(ActiveCell.Row)).Value, "HH:MM:SS") & "' AND LOGCALL_TABLE.ClientName like '" & Range("B" & CStr(ActiveCell.Row)).Value & "' AND LOGCALL_TABLE.Representative like '" & Range("C1").Value & "' and LOGCALL_TABLE.DateOnCall like '" & Date & "';"
cmd.Execute
conn.Close
End SubI think it has to do with the date and the way it is formated in my sql statement.

.......and LOGCALL_TABLE.DateOnCall like '" & Date & "';"
cmd.Execute

i had it formated this way before as required by ms access, but that does not work.

..... and LOGCALL_DB.DateOnCall = # " & Date & " #;"

any thoughts on how to format this baby?

thanks in advance.

Alex|||I think it has to do with the date and the way it is formated in my sql statement.

.......and LOGCALL_TABLE.DateOnCall like '" & Date & "';"
cmd.Execute

i had it formated this way before as required by ms access, but that does not work.

..... and LOGCALL_DB.DateOnCall = # " & Date & " #;"

any thoughts on how to format this baby?

thanks in advance.

Alex|||to begin with, LIKE should only be used with strings

what is DateOnCall? datetime or varchar?|||Be smart and create a stored procedure in you SQL Server database that accepts StopTime, EndTime, ClientName, Representative, and DateOnCall as parameters and deletes the records you want. Then just call the procedure with the values from your spreadsheet.

...and look up the syntax and usage of the LIKE operator too. I suspect it needs wildcards, or at the very least is inappropriate for Date values (as Rudy said).

But I really think the problem is in your methodology, not your syntax...