SQL copy from tables to view in a databale

Chris Slinko 1 Reputation point
2021-04-13T17:41:01.07+00:00

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 NULL,
[Location] nvarchar NULL,
[Owner Name] nvarchar NULL,
[Owner Address] nvarchar NULL,
[Owner Address 2] nvarchar NULL,
[Style] nvarchar NULL,
[Model] nvarchar NULL,
[Stories] nvarchar NULL,
[Grade] nvarchar NULL,
[Rooms Desc] nvarchar NULL,
[Bedrooms Desc] nvarchar NULL,
[Ext Wall 1] nvarchar NULL,
[Roof Struct] nvarchar NULL,
[Roof Cover] nvarchar NULL,
[Int Wall 1] nvarchar NULL,
[Heat Type] nvarchar NULL,
[Air Cond Type] nvarchar NULL
) ON [PRIMARY]
GO

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,642 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,547 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Guoxiong 8,126 Reputation points
    2021-04-13T20:30:41.667+00:00

    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 ...
    
    0 comments No comments

  2. EchoLiu-MSFT 14,571 Reputation points
    2021-04-14T02:45:40.61+00:00

    Hi @Chris Slinko

    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.

    0 comments No comments