Named Instances SQL Server

I have two named instances in my SSMS using SS08
If i connect to both instances
Both Instances have same DB (Cars)
If i open a Querry window and create a table with following syntax(attached Code Snippet)

A Table was created in Instance SYED but not in DEVDB ?

Why so ?

How do i direct the operations/Commands to a particular Instance ?

I have two instances SYED and DEVDB (attached Image)


USE Cars
CREATE TABLE Rental_Cars
     ( 
        CarID               INT                NOT NULL  , 
        brandname         VARCHAR(20)          NULL  , 
        modelname          VARCHAR(30)         NULL  , 
        manuf_year        INT				   NULL,
        CONSTRAINT PK_Rental_Cars PRIMARY KEY CLUSTERED (CarID ASC) 
        ON [PRIMARY] 
     )
GO

Open in new window

Capture.PNG
LVL 1
misermiceAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RiteshShahCommented:

CREATE TABLE Syed.Cars..Rental_Cars
     (
        CarID               INT                NOT NULL  ,
        brandname         VARCHAR(20)          NULL  ,
        modelname          VARCHAR(30)         NULL  ,
        manuf_year        INT                           NULL,
        CONSTRAINT PK_Rental_Cars PRIMARY KEY CLUSTERED (CarID ASC)
        ON [PRIMARY]
     )
GO



CREATE TABLE DEVDB.Cars..Rental_Cars
     (
        CarID                INT                NOT NULL  ,
        brandname          VARCHAR(20)          NULL  ,
        modelname          VARCHAR(30)          NULL  ,
        manuf_year        INT                           NULL,
         CONSTRAINT PK_Rental_Cars PRIMARY KEY CLUSTERED (CarID ASC)
         ON [PRIMARY]
     )
GO

0
RiteshShahCommented:
observe, there was a two dot before table name, if you want to use specific schema name, you can put it between two dot, otherwise it will use default schema, may be "DBA".
0
Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
Connect to Syed instance in SSMS and then execute the create table statement in that instance on Cars database.
Similarly connect to Devdb instance in SSMS and then execute the create table statement in that instance on Cars database.

You can't create table in both instances from a single connection.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

RiteshShahCommented:
you can right click on database and click on "New Query" option on each database and create table. Above answer is right, you can't make table in both DB from one connection. However, you can access table from the four part naming convention (if you have permission though) as  I told you above but can't create table.
0
misermiceAuthor Commented:
So is this the FOUR PART NAMING CONVENTION?

SELECT * FROM SERVER.DATABASE.OWNER/SCHEMA.OBJECT

IF SO..

Is Instance synonymous to OWNER/SCHEMA ? (SYED or DEVDB in my case) ?
0
RiteshShahCommented:
no, server is synonymous  to SYED or DEVDB. actually there should be full server name, especially if it is a named instance.
0
Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
>> Is Instance synonymous to OWNER/SCHEMA

No, this is how instances and other objects are organized.

Single server (machine)
-> n Instances
--> Each instances can have n no. of databases
---> Instances can have schema and tables inside it

>> SERVER.DATABASE.OWNER/SCHEMA.OBJECT

Four part naming refers to servername.dbname.schemaname.tablename

And you can use four part naming if you have created Linked server to your other instance.
Without which you can't create tables in your other instance.
0
misermiceAuthor Commented:
But When i try to access

a particular DB say Cars

like
USE SYED.CARS
SELECT * FROM sys.Tables

or

USE DEVDB.CARS
SELECT * FROM sys.Tables

It says

Database SYED doest not exist and  Database DEVDB doest not exist respectively
Why is not identifying Instance specific commands ?

Am i accessing it in wrong way ?
0
Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
You need to get clarified between Instances and Databases in it and the way you need to create tables inside Cars database in both of those instances

Connect to your Syed instance in SSMS, Right click it and then choose a New Query and then try

USE cars
-- CREATE table statement here
-- Issue select * from sys.tables to get it created

Similarly connect to your DevDB instance and follow the steps mentioned above.
Else you will get the errors mentioned above..
0
cyberkiwiCommented:
Just rephrasing what other experts said:

>>How do i direct the operations/Commands to a particular Instance ?
Right-click on the database in the right instance on the tree on the left - "New Query" - this will be the instance your SQL will run against.
You must do this if you want to create table or perform DDL operations.

>>So is this the FOUR PART NAMING CONVENTION?
select * from [ZAFAR-PC\DEVDB].Cars.sys.objects
select * from [.\SYED].Cars.sys.objects

But for the 4-part naming to work, you need to link the servers first.  For example, run this from ZAFAR...
Replace rmtuser and rmtpassword with the login to connect to .\syed

sp_addlinkedserver [.\SYED]
sp_addlinkedsrvlogin [.\SYED], @rmtuser = 'rmtuser', @rmtpassword= 'rmtpassword'
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.