Mar 30, 2014

Cannot perform alter on '' because it is an incompatible object type.


Suppose in any database there is table tblTargent

CREATE TABLE tblTarget(
    ID INT IDENTITY(1,1) PRIMARY KEY,
    vcData VARCHAR(500)
)

Now if try to Alter table tblTargert into VIEW like this :

ALTER VIEW tblTarget
AS
    SELECT * FROM tblOrder

We will get error message like :

Cannot perform alter on '' because it is an incompatible object type.

Cause: In sql server, we cannot alter one object to another object type likes:
1. Table to view or vice versa
2. Stored procedure to function or vice versa
3. Scalar function to tabled valued function or vice versa

Solution:

1. Use different object name. For example:

CREATE VIEW vewTarget
AS
    SELECT * FROM tblOrder

2. First drop the existing object then create it. For example:

DROP TABLE tblTarget

CREATE VIEW tblTarget
AS
    SELECT * FROM tblOrder

No comments:

Post a Comment