Showing posts with label duplicate. Show all posts
Showing posts with label duplicate. Show all posts

Wednesday, March 7, 2012

Copy and past tables

Goodday

Can anyone help please.

I have made a database and need to duplicate the tables to represent new catogaries. The definitions in the tables will stay the same , just the table names will change.

Is there a way to copy and past / duplicate tables without retyping all the definitions each time.

Thanks

Rob

hi Rob,

robhare wrote:

Goodday

Can anyone help please.

I have made a database and need to duplicate the tables to represent new catogaries. The definitions in the tables will stay the same , just the table names will change.

this does not seems to be a "good design" pattern... you should normalize your design where your main "object"' references another table for the relative categories... something like

SET NOCOUNT ON;

USE tempdb;

GO

CREATE TABLE dbo.Categories (

Id int NOT NULL PRIMARY KEY,

Description varchar(10) NOT NULL

);

CREATE TABLE dbo.myObjects (

Id int NOT NULL PRIMARY KEY,

Description varchar(10) NOT NULL,

IdCategory int NOT NULL

CONSTRAINT fk_myObject$has$category

FOREIGN KEY

REFERENCES dbo.Categories (Id)

);

GO

INSERT INTO dbo.Categories VALUES ( 1 , 'cat1');

INSERT INTO dbo.Categories VALUES ( 2 , 'cat2');

INSERT INTO dbo.myObjects VALUES ( 1 , 'a', 1 );

INSERT INTO dbo.myObjects VALUES ( 2 , 'b', 1 );

INSERT INTO dbo.myObjects VALUES ( 3 , 'c', 2 );

SELECT o.Id, o.Description, c.Id, c.Description

FROM dbo.myObjects o

INNER JOIN dbo.Categories c ON c.Id = o.IdCategory;

GO

DROP TABLE dbo.myObjects, dbo.Categories;

--<-

Id Description cat_id cat_description

-- -- --

1 a 1 cat1

2 b 1 cat1

3 c 2 cat2

when you require "additional" categories, you just have to add a new entry in the relative table...

Is there a way to copy and past / duplicate tables without retyping all the definitions each time.

if you really want to, just "script" the object Data Definition Language out with SQL Server Management Studio Express... modify the object's name as long as all the eventual constraints and execute the modified script..

regards

Friday, February 24, 2012

Coping Database objects from one database to another blank database.

I want to create a duplicate database in sql 2000 using asp.net from a webform
I created a database using CREATE DATABASE ......
But how to copy tables, views, stored procedures to newly created
database from old using asp.net from webform
Is there any another method to create a duplicate database with another name
from existing database on same server ?

yes you can do have another DB with different name and that has everything the same ....!!!|||One way it can be done is with the backup database command. You can backup a database, create a new database and then restore the backup to the new database. This can all be done in batch scripts and with T-SQL. Take a look at this link on MSDN, also look at the RESTORE links down at the bottom.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ba-bz_35ww.asp
Hope this helps
|||

The easiest is to use the Restore option of the Backup and Restore wizard, choose the restore from a Device option click on the wizard to locate your .bak file and SQL Server will ask you for a name for the new version. If the restore is not successfull delete it and start again. Hope this helps.

|||Hello,
I have project of a company having 15 branches allover.
I want to create a seperate database for each branch.
When a customer register a new branch new database should be created.
Thank for the reply
|||

If you are just creating Databases all you need are fifteen connection strings in your Web.config by creating new app setting section for each database. If you need the databases in separate servers you have to register all servers in your SQL Server and create the databases. When you are connecting to SQL Server you are accessing none .NET managed resource so I think you should plan and test all options and your users creating databases on login should not be one of them. Hope this helps.