I am creating a smaller sized database in Microsoft SQL Server 2012 to keep run data from machines. The company has production machines and R & D machines. I would like to use the same table for production and R&D with a Type field specifying what the run was for simplicity. I have two schemas (prod and r_d). The permissions for the production and r_d schemas will be different. Is it possible to create a table that belongs to more than one schema? I know you can have the same table name in multiple schemas, but this creates separate objects. I would like to have the one table object to belong to multiple schemas.
Example:
CREATE TABLE db_name.prod.r_d.table_name
Consider creating a synonym in one the of schemas, referencing the other schema table:
CREATE SYNONYM r_d.table_name FOR prod.table_name;
No, but you can create a view in each schema on to a single table that filters the rows
When you said Development and Production. You should consider using separate database and as we go separate server !
For sampling the data you could use a backup of the production database. If you don't want the dev team to have access to production data (avoid data leak), they have to generate their sample data themselves.
Using Synonym or View in your case looks like a bad and dangerous practice !
Related
Not:
DROP -> CREATE
I need:
COMPARE -> ALTER
I have a test and a production database, the data withing these two are different but the schemas should be the same.
I need something like a production script or a tool or a method which compare these two dbs schema and sync them. I'm coding in nodejs and the thing is I haven't used tools like an ORM or db-migrate, I've created the database using MYSQL-workbench and it costs a lot to write every alter query. there must be an easier way.
I use oracle as my database.
I am confused with the concept between schema and database. I looked around here and couldn't find any explicit defined example.
Suppose we have a QA, DEV and production environment and suppose I have three QA environments. Between the three QA environment, will they generally have different database or different schema?
Suppose those three different QA environments have different data in each environment. And suppose I want to create a new fourth QA environment and want to copy a table (lets call this table foo) from one of the already existing QA environment (lets call this environment QA_1) to the new QA environment (lets call this QA_NEW). Will I be copying the schema table foo from QA_1 to QA_NEW or will I be copying the database table from QA_1 to QA_NEW?
You will want to copy the entire database to the new environment so that all environments match.
A schema is similar to a namespace. A database can have multiple namespaces and you'll likely want to copy all.
databases are physical (data files, blocks. etc.).
schemas are usernames (owners) of logical storage objects (tables, mviews, etc.) within the database
In your case, you have 3 QA databases (QA_1, QA_2 .. QA_N), each with their own schemas - likely of the same schema names (usernames). You'd be copying the database.schema.table to another database.schema.table
QA_1.myschema.foo -> QA_2.myschema.foo
You'd say "Foo table lives in the QA_1 database and is owned by the 'myschema' schema."
Server1: Prod, hosting DB1
Server2: Dev hosting DB2
Is there a way to query databases living on 2 different server with a same select query? I need to bring all the new rows from Prod to dev, using a query
like below. I will be using SQL Server DTS (import export data utility)to do this thing.
Insert into Dev.db1.table1
Select *
from Prod.db1.table1
where table1.PK not in (Select table1.PK from Dev.db1.table1)
Creating a linked server is the only approach that I am aware of for this to occur. If you are simply trying to add all new rows from prod to dev then why not just create a backup of that one particular table and pull it into the dev environment then write the query from the same server and database?
Granted this is a one time use and a pain for re-occuring instances but if it is a one time thing then I would recommend doing that. Otherwise make a linked server between the two.
To backup a single table in SQL use the SQl Server import and export wizard. Select the prod database as your datasource and then select only the prod table as your source table and make a new table in the dev environment for your destination table.
This should get you what you are looking for.
You say you're using DTS; the modern equivalent would be SSIS.
Typically you'd use a data flow task in an SSIS package to pull all the information from the live system into a staging table on the target, then load it from there. This is a pretty standard operation when data warehousing.
There are plenty of different approaches to save you copying all the data across (e.g. use a timestamp, use rowversion, use Change Data Capture, make use of the fact your primary key only ever gets bigger, etc. etc.) Or you could just do what you want with a lookup flow directly in SSIS...
The best approach will depend on many things: how much data you've got, what data transfer speed you have between the servers, your key types, etc.
When your servers are all in one Active Directory, and when you use Windows Authentification, then all you need is an account which has proper rights on all the databases!
You can then simply reference all tables like server.database.schema.table
For example:
insert into server1.db1.dbo.tblData1 (...)
select ... from server2.db2.dbo.tblData2;
I'm using two databases test and prod in the same SQL Server instance. The databases share the same data structure but contains different data, is there an easy way to synchronize the structure between the two so if I modify a table in test automatically update also the same table in prod?
You could write a trigger on the table in test which uses a MERGE to update the table in prod...
I would be careful of persisting changes made in a test environment to a prod environment automatically though.
I would like to know which one is the best approach for migrating existing DB data to another new DB with entirely different structure. I want to copy the data from my old DB and need to insert the data in new DB. For me the table names and column names of new DB is entirely different. I am using SQL Server 2008.
You should treat this as an ETL problem, not a migration, as the two schemas are entirely different. The proper tool for this is SSIS. SSIS allows you to create dataflows that map columns from one table to another, add derived sources, perform splits, merges, etc. If possible you should create source queries that return results close to the schema of the target database so you need fewer transformations.
In this you have to migrate most of the parts manually by running scripts. AFAIK automatically it will not synchronize. But using SSMS you Map tables of two different db's. hope that will help.