Answer the question
In order to leave comments, you need to log in
How to fix "There is already an object named ... in the database" error?
Wrote the first script for MS SQL Server.
The first time I launched it - it worked fine.
Now I get the error "There is already an object named ... in the database".
Script:
-- начинаем работать в контексте системной базы данных [master]
USE [master]
GO
-- если база данных [dbRBL] уже существует, уничтожаем ее
IF EXISTS (SELECT name FROM sys.databases WHERE name = N'dbRBL')
DROP DATABASE [dbRBL]
GO
-- создаём базу данных [dbRBL]
CREATE DATABASE [dbRBL]
GO
-- переходим в контекст созданной базы данных [dbRBL]
USE [dbSPJ]
GO
-- создаём таблицу читателей [R]
CREATE TABLE [dbo].[R] (
[Rno] [int] IDENTITY(1,1) NOT NULL,
[Rname] [varchar](100) NOT NULL,
[Rsex] [varchar](10) NULL,
[Rbirthday] [date] NULL,
[Rphone] [varchar](30) NULL
)
GO
-- создаём таблицу книг [B]
CREATE TABLE [dbo].[B] (
[Bno] [int] IDENTITY(1,1) NOT NULL,
[Bname] [varchar](100) NOT NULL,
[Bauthor] [varchar](100) NULL,
[Byear] [date] NULL,
[Bpages] [int] NULL,
[Bweight] [int] NULL,
[Bcopies] [int] NULL
)
GO
-- создаём таблицу библиотек [L]
CREATE TABLE [dbo].[L](
[Lno] [int] IDENTITY(1,1) NOT NULL,
[Ladress] [varchar](150) NOT NULL,
[Ldate] [date] NULL,
[Lquantity] [int] NULL,
[Lphone] [varchar](30) NULL
)
GO
-- создаём таблицу записей
CREATE TABLE [dbo].[RBL](
[Rno] [int] NOT NULL,
[Bno] [int] NOT NULL,
[Lno] [int] NOT NULL,
[RBLdate] [date] NULL
)
GO
Answer the question
In order to leave comments, you need to log in
-- switch to the context of the created database [dbRBL]
USE [dbSPJ]
GO
database name error.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question