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
SSC Eights!
SSC Eights! (862 reputation)SSC Eights! (862 reputation)SSC Eights! (862 reputation)SSC Eights! (862 reputation)SSC Eights! (862 reputation)SSC Eights! (862 reputation)SSC Eights! (862 reputation)SSC Eights! (862 reputation)

Group: General Forum Members
Points: 862 Visits: 256
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 (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)

Group: General Forum Members
Points: 52036 Visits: 16668
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
SSC Eights!
SSC Eights! (862 reputation)SSC Eights! (862 reputation)SSC Eights! (862 reputation)SSC Eights! (862 reputation)SSC Eights! (862 reputation)SSC Eights! (862 reputation)SSC Eights! (862 reputation)SSC Eights! (862 reputation)

Group: General Forum Members
Points: 862 Visits: 256
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 (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)

Group: General Forum Members
Points: 89817 Visits: 6925
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