question

ChrisSlinko-7749 avatar image
0 Votes"
ChrisSlinko-7749 asked EchoLiu-msft commented

SQL copy from tables to view in a databale

I have a table that is in a database and I would like to copy it to the Views table I'm getting an error. Below are the errors

Msg 911, Level 16, State 1, Line 1
Database 'Views' does not exist. Make sure that the name is entered correctly.

Msg 2714, Level 16, State 6, Line 2
There is already an object named 'VW_vision_for_fire' in the database.

Code

USE [Views]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[VW_vision_for_fire]
(
[REM_GIS_ID] [nvarchar](255) NULL,
[Location] [nvarchar](255) NULL,
[Owner Name] [nvarchar](255) NULL,
[Owner Address] [nvarchar](255) NULL,
[Owner Address 2] [nvarchar](255) NULL,
[Style] [nvarchar](255) NULL,
[Model] [nvarchar](255) NULL,
[Stories] [nvarchar](255) NULL,
[Grade] [nvarchar](255) NULL,
[Rooms Desc] [nvarchar](255) NULL,
[Bedrooms Desc] [nvarchar](255) NULL,
[Ext Wall 1] [nvarchar](255) NULL,
[Roof Struct] [nvarchar](255) NULL,
[Roof Cover] [nvarchar](255) NULL,
[Int Wall 1] [nvarchar](255) NULL,
[Heat Type] [nvarchar](255) NULL,
[Air Cond Type] [nvarchar](255) NULL
) ON [PRIMARY]
GO

sql-server-generalsql-server-transact-sql
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Do you have anyupdate?
Please also remember to accept the answers if they helped. Your action would be helpful to other users who encounter the same issue and read this thread.

0 Votes 0 ·
GuoxiongYuan-7218 avatar image
0 Votes"
GuoxiongYuan-7218 answered GuoxiongYuan-7218 edited

In the USE [Views] statement, Views is an existing database name. It seems you do not have that database named Views.

 USE [DATABASE_NAME];
 GO
    
 CREATE TABLE ...


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

EchoLiu-msft avatar image
0 Votes"
EchoLiu-msft answered EchoLiu-msft edited

Hi @ChrisSlinko-7749

Welcome to the microsoft TSQL Q&A forum!

87499-image.png
Guoxiong has already explained the reason for the error. In addition, I want to add that please check again whether the database name you want to use is Views. If it is View, if you enter Views, similar errors will be returned.

87490-image.png
The reason for this error is: CREATE TABLE statement will create a new table, if the table already exists before, it will return the above error.In other words, before running

 CREATE TABLE [dbo].[VW_vision_for_fire]. . .

Statement, the [dbo].[VW_vision_for_fire] table already exists in your database. It is also possible that you have repeatedly executed

 CREATE TABLE [dbo].[VW_vision_for_fire]. . .

To solve this problem, just execute DROP TABLE npub_info before executing CREATE TABLE [dbo].[VW_vision_for_fire]...

If you have any question, please feel free to let me know.
If the response is helpful, please click "Accept Answer" and upvote it.


Regards
Echo


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



image.png (10.5 KiB)
image.png (10.3 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.