473,473 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Integrity between table and View

It is possible to drop the table without dropping the view referencing
it. How do I force integrity?

Madhivanan

Jul 23 '05 #1
9 2073
No you can't. What do you mean by 'force integrity'? A view is always kept
in sync with the table(s) on which it is based.

--
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine

This posting is provided "AS IS" with no warranties, and confers no rights.

"Madhivanan" <ma************@gmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
It is possible to drop the table without dropping the view referencing
it. How do I force integrity?

Madhivanan

Jul 23 '05 #2
Think about this for two seconds. If there is no base table, how would
you build the VIEW???

Jul 23 '05 #3
Yes, you can drop a table when referencing views exist unless views are
created with the WITH SCHEMABINDING option. The view will be invalid in
that case. You can specify WITH SCHEMABINDING on your views to prevent
invalid views.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Madhivanan" <ma************@gmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
It is possible to drop the table without dropping the view referencing
it. How do I force integrity?

Madhivanan

Jul 23 '05 #4
What do you mean by 'force integrity'?

I want to get the error, This table is referenced by a view

Think about this for two seconds. If there is no base table, how would

you build the VIEW???

I think you didnot understand my question

Yes, you can drop a table when referencing views exist unless views are

created with the WITH SCHEMABINDING option.

Thanks

Madhivanan

Jul 23 '05 #5
No error will be generated when you drop a table referenced in a view
unless the view is indexed. Maybe you can index your view(s), although
in my opionion you shouldn't need to do so just for this. Surely you
wouldn't drop a table in production without first testing your code? If
the table or view is used in code then testing will show an error. If
the table or view isn't used then it isn't relevant. MS could have
implemented it better but unfortunately they didn't.

--
David Portas
SQL Server MVP
--

Jul 23 '05 #6
David Portas (RE****************************@acm.org) writes:
No error will be generated when you drop a table referenced in a view
unless the view is indexed. Maybe you can index your view(s), although
in my opionion you shouldn't need to do so just for this. Surely you
wouldn't drop a table in production without first testing your code? If
the table or view is used in code then testing will show an error. If
the table or view isn't used then it isn't relevant. MS could have
implemented it better but unfortunately they didn't.


You don't need to go all the way and index the view. As Dan said,
what you need is WITH SCHEMABINDING. Try this:
CREATE TABLE mytable (a int NOT NULL)
go
CREATE VIEW myview WITH SCHEMABINDING AS
SELECT a FROM mytable
go
DROP TABLE mytable -- Fails

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #7
Ernold,

I get the error
Server: Msg 4512, Level 16, State 3, Procedure myview, Line 2
Cannot schema bind view 'myview' because name 'mytable' is invalid for
schema binding. Names must be in two-part format and an object cannot
reference itself.

Madhivanan

Jul 23 '05 #8
Madhivanan (ma************@gmail.com) writes:
I get the error
Server: Msg 4512, Level 16, State 3, Procedure myview, Line 2
Cannot schema bind view 'myview' because name 'mytable' is invalid for
schema binding. Names must be in two-part format and an object cannot
reference itself.


Oops! I tested, got an error messages, was contented with that. I failed
to read the error message, though. OK, try this then:

CREATE TABLE mytable (a int NOT NULL)
go
CREATE VIEW myview WITH SCHEMABINDING AS
SELECT a FROM dbo.mytable
go
DROP TABLE mytable -- Fails

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #9

No it works well
Thanks Erland

Madhivanan

Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nagib Abi Fadel | last post by:
HI, let's say i have a tansaction table called TRANSACTION (transaction_id,amount,type,type_id) Let's say a transaction can have multiple types: TYPE1, TYPE2 for example. EACH type has his...
4
by: maricel | last post by:
I have the following base table structure - DDL: CREATE TABLE "ADMINISTRATOR"."T1" ( "C1" INTEGER NOT NULL ) IN "TEST_TS" ; ALTER TABLE "ADMINISTRATOR"."T1" ADD PRIMARY KEY
1
by: Grant McLean | last post by:
Hi First a simple question ... I have a table "access_log" that has foreign keys "app_id" and "app_user_id" that reference the "application_type" and "app_user" tables. When I insert into...
7
by: Jimmie H. Apsey | last post by:
Referential Integrity on one of our production tables seems to have been lost. I am running Postgres 7.1.3 embedded within Red Hat kernel-2.4.9-e.49. Within that I have a table with referential...
6
by: heyvinay | last post by:
I have transaction table where the rows entered into the transaction can come a result of changes that take place if four different tables. So the situation is as follows: Transaction Table...
12
by: technocrat | last post by:
I am trying to laod 2 tables and set integrtiy on them, but the second tables fails ( both are related and SET INTEGRITY ion first table succeeds) saying constraint violation....is there a way to...
16
by: Brian Tkatch | last post by:
Is there a way to check the order in which SET INTEGRITY needs to be applied? This would be for a script with a dynamic list of TABLEs. B.
1
by: Brian Tkatch | last post by:
A few questions about SET INTEGRITY. 1) Docs: The SET INTEGRITY statement is under transaction control. Using two sessions (different user, even) i tried the following. Session 1: UPDATE...
2
by: ApexData | last post by:
Access2000, using a continuous form. I’m getting a message that say “you cannot add or change a record because a related record is required in table Employee”. This occurs in all my combobox...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.