SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


USE statement inside create view statement possible?


USE statement inside create view statement possible?

Author
Message
Jackie Lowery
Jackie Lowery
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1128 Visits: 277
I would like to create a view in a database that gets data from another database. Here is beginning of statement:


create view data_01..EDISent as
USE edi_01
GO
......


The USE statement is underlined in red. Can i not have a USE statement inside a create view statement?

pietlinden
pietlinden
SSC Guru
SSC Guru (54K reputation)SSC Guru (54K reputation)SSC Guru (54K reputation)SSC Guru (54K reputation)SSC Guru (54K reputation)SSC Guru (54K reputation)SSC Guru (54K reputation)SSC Guru (54K reputation)

Group: General Forum Members
Points: 54528 Visits: 17290
Why not just use a the 3-part naming convention when creating your view?

USE Tempdb;
GO
CREATE VIEW MyView
AS
SELECT CustomerID
FROM Galactic.dbo.Customer;


I'm creating a view inside one database (tempdb) that gets data from another database (Galactic).

Jackie Lowery
Jackie Lowery
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1128 Visits: 277
pietlinden - Saturday, February 17, 2018 1:31 PM
Why not just use a the 3-part naming convention when creating your view?

USE Tempdb;
GO
CREATE VIEW MyView
AS
SELECT CustomerID
FROM Galactic.dbo.Customer;

You're right. USE is not allowed in views or stored procedures apparently. Thanks.

sgmunson
sgmunson
SSC Guru
SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)

Group: General Forum Members
Points: 98401 Visits: 7265
Jackie Lowery - Saturday, February 17, 2018 1:35 PM
pietlinden - Saturday, February 17, 2018 1:31 PM
Why not just use a the 3-part naming convention when creating your view?

USE Tempdb;
GO
CREATE VIEW MyView
AS
SELECT CustomerID
FROM Galactic.dbo.Customer;

You're right. USE is not allowed in views or stored procedures apparently. Thanks.

That's because the USE statement isn't a query element, it's a batch directive, similar to GO in that respect.


Steve
‌(aka sgmunson)
Smile Smile Smile
Health & Nutrition
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum









































































































































































SQLServerCentral


Search