sql server - Using stored procedures of another database -


I have database1 There are some procedures in the I / code> statement.

The tables I want to fill in are in database2 . How can I write a question with EXEC procedures to fill those tables?

I do not want to add stored procedures in the same database of tables ( database2 )

This is one of the procedures stored in DB1

  USE [database1] Go SET ANSI_NULLS Go set to go change process QUOTED_IDENTIFIER [dbo] [Subject] ([code], [credit], [hour] value (@medical code) [subject ] [Subject] ([code], [credit], [code], @ credits, @horse] @@ identity   

and here is where I execute the stored procedure I:

  EXEC @ subid = [database1]. [DBO]. [Add topic] @icicode = '1234', @ credit = 2, @ hours = 50   

and it gives me an error:

  Message 208 , Level 16, State 1, Process AddSubject, Line 14 Invalid Object Name 'database2.dbo.Subject'    

You can reference SQL Server tables with one:

  server.database.schema.table   

A different database You only need the last three parts:

  Insert other db.dbo.yourtable (Col1, col2, ...) values ​​('val1', 'val2', ... )   

You can use it in a stored procedure to insert a table into a separate database.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -