Thursday, March 22, 2012

database extension in MS SQL?

hello ... I am trying to copy 1 field from a table in database called DB1 to a same table in DB2 .. I am not sure if this is possible. I found out form www3.schools.com it's doable using Select Into ... but it uses MS Access for example (Northwind.mdb) ... I wonder what's the extension database in MS SQL? Does anyone know where can we check the query syntax on the web? Can anyone tell me it's correct? I dun have MS SQL from home .. so :(

======copy prodID from DB1 to DB2 table called production1 (both DB1 and DB2)=======

// this is done in SQL QUERY ANALYZER under DB1?

SELECT production1.prodID INTO production1 IN DB2 FROM DB1

=====create VIEW in DB2=======

// this has to be done in DB1 ... if I have multiple databases, is there anyway to do it using something like SELECT INTO to create view in differences databases?

CREATE VIEW production_id AS SELECT prodID from DB1

Assuming that you're running against a SQL Server instance, and not directly mounting the database files, you don't need to know the file names. If both databases are on the same server, you can reference tables on another database as [database].[owner].[table]. So, if you're logged into db2, you could do

insert into production1 select db1.production1.prodID

No comments:

Post a Comment