Showing posts with label constraints. Show all posts
Showing posts with label constraints. Show all posts

Wednesday, March 21, 2012

How can I migrate all objects alogwith all constraints,SP,Triggers etc from Development instance

Hi fellows,

I have to migrate all objects alogwith all constraints,SP,Triggers, indexes etc from Development instance to Production instance of a DB, all those things are created through wizard ie. Sql server 2000 Enterprise Manager. if i use DTS it only mirates data along with tables and views but constraints,SP,Triggers, indexes etc not yet copied.

can any body help me how can I solve this problem by copying all objects alogwith all constraints,SP,Triggers etc from Development instance to Production instance.

This is Sql server 2000 Cluster environment.

thanks in advance for any help

rahman

I would script all the objects out using Enterprise Manager and then run them all in the other environment.

-Jamie

|||

Dear Jamie

Thank you very much for your reply

would you like to give me a hence to write script for all the object's constraints (ie. Default,Check,Primary Key, Foreign Key etc) and indexes using Enterprise Manager.

I am new in SQL Server

Thanks in advance

|||

1. Right-click on an object.

2. Point at All tasks--> Generate SQL Script...

-Jamie

|||

Dear Jamie

Thanks for your reply.

I know this script only create table/view but not any constrains attached with it. As you know DTS also creates Table/views and imports the data too.

it'll not solve the problem, I m trying to write scripts for constraints getting info. from some views of Information_Schema.

|||

Thanks Jamie,

I didn't see the options available in Options Tab of All tasks--> Generate SQL Script

thank you very much

sql

How can I migrate all objects alogwith all constraints,SP,Triggers etc from Development inst

Hi fellows,

I have to migrate all objects alogwith all constraints,SP,Triggers, indexes etc from Development instance to Production instance of a DB, all those things are created through wizard ie. Sql server 2000 Enterprise Manager. if i use DTS it only mirates data along with tables and views but constraints,SP,Triggers, indexes etc not yet copied.

can any body help me how can I solve this problem by copying all objects alogwith all constraints,SP,Triggers etc from Development instance to Production instance.

This is Sql server 2000 Cluster environment.

thanks in advance for any help

rahman

I would script all the objects out using Enterprise Manager and then run them all in the other environment.

-Jamie

|||

Dear Jamie

Thank you very much for your reply

would you like to give me a hence to write script for all the object's constraints (ie. Default,Check,Primary Key, Foreign Key etc) and indexes using Enterprise Manager.

I am new in SQL Server

Thanks in advance

|||

1. Right-click on an object.

2. Point at All tasks--> Generate SQL Script...

-Jamie

|||

Dear Jamie

Thanks for your reply.

I know this script only create table/view but not any constrains attached with it. As you know DTS also creates Table/views and imports the data too.

it'll not solve the problem, I m trying to write scripts for constraints getting info. from some views of Information_Schema.

|||

Thanks Jamie,

I didn't see the options available in Options Tab of All tasks--> Generate SQL Script

thank you very much

Friday, March 9, 2012

How can I INSERT w/Constraints in other tables?

Three tables (all new, no data) will receive data from dBase and be
transposed into them...All three have auto generated IDENTITY columns
and pk and fk constraints. Can someone provide me with an
understandible sample?
Thanks,
TrintThis example may help. Assuming your tables look like this:

CREATE TABLE Foo (foo_id INTEGER IDENTITY PRIMARY KEY, foo_key
VARCHAR(10) NOT NULL UNIQUE)

CREATE TABLE Bar (bar_id INTEGER IDENTITY PRIMARY KEY, bar_key
VARCHAR(10) NOT NULL UNIQUE, foo_id INTEGER NOT NULL REFERENCES Foo
(foo_id))

And assuming you have a similar source structure from dBase, here are
the INSERTs:

INSERT INTO Foo (foo_key)
SELECT DISTINCT foo_key
FROM Foo_source

INSERT INTO Bar (bar_key, foo_id)
SELECT DISTINCT B.bar_key, F2.foo_id
FROM Bar_source AS B
JOIN Foo_source AS F
ON B.foo_id = F.foo_id
JOIN Foo AS F2
ON F.foo_key = F2.foo_key

For this to work you do of course need the alternate key ("foo_key" in
this case). That shouldn't be a problem. IDENTITY should never be the
only key of a table.

--
David Portas
SQL Server MVP
--|||David,
Here are the two tables...can you help in using the example with them?::

CREATE TABLE [tblTravelDetailMember] (
[TravelDetailUplineId] [int] NOT NULL ,
[TravelDetailId] [int] NOT NULL ,
[TravelDetailMemberTypeId] [int] NOT NULL ,
[memberId] [bigint] NOT NULL ,
[rankId] [int] NOT NULL ,
[CreatedDateTime] [datetime] NOT NULL ,
[Operator] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
CONSTRAINT [PK_tblTravelDetailMember] PRIMARY KEY CLUSTERED
(
[TravelDetailUplineId]
) ON [PRIMARY] ,
CONSTRAINT [FK_tblTravelDetailMember_tblTravelDetail] FOREIGN KEY
(
[TravelDetailId]
) REFERENCES [tblTravelDetail] (
[TravelDetailId]
),
CONSTRAINT [FK_tblTravelDetailMember_tblTravelDetailMemberType ] FOREIGN
KEY
(
[TravelDetailMemberTypeId]
) REFERENCES [tblTravelDetailMemberType] (
[TravelDetailMemberTypeId]
)
) ON [PRIMARY]
GO

------

CREATE TABLE [tblTravelDetailMemberType] (
[TravelDetailMemberTypeId] [int] NOT NULL ,
[Description] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[CreatedDateTime] [datetime] NOT NULL ,
[Operator] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
CONSTRAINT [PK_tblTravelDetailMemberType] PRIMARY KEY CLUSTERED
(
[TravelDetailMemberTypeId]
) ON [PRIMARY]
) ON [PRIMARY]
GO

I get this error with this code:
string strSQL2 = "INSERT INTO tblTravelDetailMember(memberId, " +
" TravelDetailUplineId, " +
" rankId, " +
" TravelDetailId, " +
" CreatedDateTime, " +
" Operator) " +
"VALUES ('" + insertString2 + "', " +
" '" + insertString3 + "', " +
" '" + insertString4 + "', " +
" '" + insertString5 + "', " +
" '" + insertString6 + "', " +
" '" + insertString7 + "')";

Thanks,
Trint

Net programmer
trinity.smith@.gmail.com

*** Sent via Developersdex http://www.developersdex.com ***|||You didn't specify what error message you are getting. You didn't
include the alternate keys or the IDENTITY properties that you said you
had. The only obvious problem with your INSERT is that you've missed
out one of the columns ("TravelDetailMemberTypeId").

Put the INSERT in a stored procedure rather than construct a SQL string
in your app. That way you can test and check the code more easily.

If you only want to insert rows one at a time then you should be able
to make use of the SCOPE_IDENTITY() function to do this. See Books
Online for details. I was assuming you would load all the data with one
INSERT per table.

--
David Portas
SQL Server MVP
--