Showing posts with label generated. Show all posts
Showing posts with label generated. Show all posts

Thursday, March 22, 2012

Creating tables with SQL Scripts (SOLVED)

In sql server 2003 I would create tables with generated sql scripts.
This way I could easily create duplicate dev environments.

Now in SQL 2005 Dev edition I try to run my scripts to create tables.
I create a db [MSS].
They run successfully but there is no table created.

(example script)USE [MSS]
GO
/****** Object: Table [dbo].[KataNames] Script Date: 08/17/2006 13:28:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[KataNames](
[Kata] [char](30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[SequenceId] [int] IDENTITY(1,1) NOT NULL,
[Description] [char](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Style] [char](25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF

Any clue what else I have to do to let these scripts actually create tables or why if they run ok, where is my table ?

Thanks

Kim AllbritainDid you 'Refresh' the table list in SSMS?|||Right click your "Databases" node and choose "Refresh"|||Of course I refreshed the db list. I even restarted the app and looked again. No table, but successful completion of the script every time.

Is it possible to back up a sql 200 db on one machine and restore it to 2005 sql on another?|||

KAllbritain wrote:

Of course I refreshed the db list. I even

restarted the app and looked again. No table, but successful completion

of the script every time.

Is it possible to back up a sql 200 db on one machine and restore it to 2005 sql on another?

There isnt much point saying "Of course I did" we diddnt know that you did "yes I tried that" would have been much nicer

Ok, are you using an application to send these scripts? Like Access or .NET

If so, the application or the user account you are using to fire the scripts may not have the appropriate permissions to do so.

Alternatively, do you mean you fired the script in the Query Analayzer of SQL Server 2005 and still do not see the tables?

Do you have serveral SQL Servers on your network?

AFAIK there is no SQL Server 2003, and with regards to porting a 2000 to 2005 yes its possible, there is some documentation here; http://www.microsoft.com/technet/prodtechnol/sql/themes/default.mspx

take it slow, let us fully understand your situation so that we can resolve it = )|||I appreciate your response.

It was sql2000 dev version using 2003 .Net

on sql2005 dev:

The scripts are loaded into the query analyzer and run from there
while connected to the proper db on my local machine.
There are no other servers presently connected.

The script indicates the proper db as well so How can it report
successful without actually performing the create table?|||

If the purpose of the script is to CREATE an object, it is not successful until after it creates that object. If you want to verify syntax, you could, in SSMS, click on the green 'checkmark' icon on the toolbar, or [Query], [Parse] on the menu, or {ctrl}{F5}.

If you want to verify that it actually works, you could wrap it in a TRANSACTION and ROLLBACK when completed.

Or run it in a 'Test' database first.

|||Thanks

The scripts purpose is create a table. It works in sql2000 fine.
The message provided after executing the script is that it was "Successful", therefore I would expect the object (table) to be created.

I am cloning a small db in a new environment, change from 2000 to 2005.
The syntax is fine.

My problem is that if the syntax is fine, the script works in sql2000,
and SSMS says it worked, why doesn't it?

What else can I do?

I could build the tables by hand but why?|||OK I solved this. Just in case anyone else reads this thread.

The table was created by my scripts alright, just not in the db I thought I was in.

I was looking at db "Library" and it was highlighted, but when I opened the Query screen and connected it defaulted to the (Master)
db, so that's where The tables were.

Would be nice if the IDE for SQl2005 would default to the
db you were actually connected and working on instead of
re-connecting to something else.

But it worked ok.

Bye

Creating tables with SQL Scripts

In sql server 2003 I would create tables with generated sql scripts.
This way I could easily create duplicate dev environments.

Now in SQL 2005 Dev edition I try to run my scripts to create tables.
I create a db [MSS].
They run successfully but there is no table created.

(example script)USE [MSS]
GO
/****** Object: Table [dbo].[KataNames] Script Date: 08/17/2006 13:28:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[KataNames](
[Kata] [char](30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[SequenceId] [int] IDENTITY(1,1) NOT NULL,
[Description] [char](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Style] [char](25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF

Any clue what else I have to do to let these scripts actually create tables or why if they run ok, where is my table ?

Thanks

Kim AllbritainDid you 'Refresh' the table list in SSMS?|||Right click your "Databases" node and choose "Refresh"|||Of course I refreshed the db list. I even restarted the app and looked again. No table, but successful completion of the script every time.

Is it possible to back up a sql 200 db on one machine and restore it to 2005 sql on another?|||

KAllbritain wrote:

Of course I refreshed the db list. I even

restarted the app and looked again. No table, but successful completion

of the script every time.

Is it possible to back up a sql 200 db on one machine and restore it to 2005 sql on another?

There isnt much point saying "Of course I did" we diddnt know that you did "yes I tried that" would have been much nicer

Ok, are you using an application to send these scripts? Like Access or .NET

If so, the application or the user account you are using to fire the scripts may not have the appropriate permissions to do so.

Alternatively, do you mean you fired the script in the Query Analayzer of SQL Server 2005 and still do not see the tables?

Do you have serveral SQL Servers on your network?

AFAIK there is no SQL Server 2003, and with regards to porting a 2000 to 2005 yes its possible, there is some documentation here; http://www.microsoft.com/technet/prodtechnol/sql/themes/default.mspx

take it slow, let us fully understand your situation so that we can resolve it = )|||I appreciate your response.

It was sql2000 dev version using 2003 .Net

on sql2005 dev:

The scripts are loaded into the query analyzer and run from there
while connected to the proper db on my local machine.
There are no other servers presently connected.

The script indicates the proper db as well so How can it report
successful without actually performing the create table?|||

If the purpose of the script is to CREATE an object, it is not successful until after it creates that object. If you want to verify syntax, you could, in SSMS, click on the green 'checkmark' icon on the toolbar, or [Query], [Parse] on the menu, or {ctrl}{F5}.

If you want to verify that it actually works, you could wrap it in a TRANSACTION and ROLLBACK when completed.

Or run it in a 'Test' database first.

|||Thanks

The scripts purpose is create a table. It works in sql2000 fine.
The message provided after executing the script is that it was "Successful", therefore I would expect the object (table) to be created.

I am cloning a small db in a new environment, change from 2000 to 2005.
The syntax is fine.

My problem is that if the syntax is fine, the script works in sql2000,
and SSMS says it worked, why doesn't it?

What else can I do?

I could build the tables by hand but why?|||OK I solved this. Just in case anyone else reads this thread.

The table was created by my scripts alright, just not in the db I thought I was in.

I was looking at db "Library" and it was highlighted, but when I opened the Query screen and connected it defaulted to the (Master)
db, so that's where The tables were.

Would be nice if the IDE for SQl2005 would default to the
db you were actually connected and working on instead of
re-connecting to something else.

But it worked ok.

Bye

Tuesday, March 20, 2012

Creating subscription using script generated by Enterprise Manager

I have a hopefully easy question that I cannot find the answer to anywhere.
I am attempting to automate the creation of an anonymous pull subscription.
I have created the subscription on one machine, and then generated a script
using Enterprise Manager to create the subscription.
When I run the subscription script, the subscription is created correctly.
However, when I run the job created to do the merge, it always fails because
the process running on the subscriber could not connect to the distributor
because of a login failure.
In the generated script, I have seen that there is an option for
SubscriberEncryptedPassword. I have generated the script in Unicode mode,
and then looking at the script in WordPad shows some non-ASCII characters as
the contents of that password. I'm assuming that the problem has to do with
this password.
I am using SQL Server authentication. Does anyone know what the problem is,
or where I should look to find the answer? I haven't been successful in any
of my searches.
Thanks for any help,
Ryan
do not use this parameter. SQL will encrypt the password you specify in the
@.distributor_password and @.publisher_password (if you specify this)
parameters.
Hilary Cotter
Looking for a book on SQL Server replication?
http://www.nwsu.com/0974973602.html
"Ryan McFall" <mcfall@.hope.edu> wrote in message
news:%23bCSNfdhEHA.644@.tk2msftngp13.phx.gbl...
> I have a hopefully easy question that I cannot find the answer to
anywhere.
> I am attempting to automate the creation of an anonymous pull
subscription.
> I have created the subscription on one machine, and then generated a
script
> using Enterprise Manager to create the subscription.
> When I run the subscription script, the subscription is created correctly.
> However, when I run the job created to do the merge, it always fails
because
> the process running on the subscriber could not connect to the distributor
> because of a login failure.
> In the generated script, I have seen that there is an option for
> SubscriberEncryptedPassword. I have generated the script in Unicode mode,
> and then looking at the script in WordPad shows some non-ASCII characters
as
> the contents of that password. I'm assuming that the problem has to do
with
> this password.
> I am using SQL Server authentication. Does anyone know what the problem
is,
> or where I should look to find the answer? I haven't been successful in
any
> of my searches.
> Thanks for any help,
> Ryan
>
|||Thanks for the tip. I'm afraid it didn't work, however.
First I edited out the @.subscriberEncryptedPassword parameter completely.
The generated script had specified @.distributor_password=N'' (and the same
for the publisher). I first tried leaving those as they were and ran the
script without the @.subscriberEncryptedPassword parameter. When that didn't
work, I entered in the password for the SQL server account specified by the
@.distributor_login parameter.
In the first case, where the passwords weren't set, I got an error that the
agent was unable to connect to the subscriber. When I entered the
appropriate password for the distributor and publisher and ran the script,
the merge agent fails with "unable to connect to distributor, invalid
password for user annotations (the SQL server account used on the publisher,
distributor and subscriber).
Maybe I'm misunderstanding what you're suggesting?
Ryan
"Hilary Cotter" <hilaryk@.att.net> wrote in message
news:egjqd5ghEHA.4064@.TK2MSFTNGP12.phx.gbl...
> do not use this parameter. SQL will encrypt the password you specify in
the[vbcol=seagreen]
> @.distributor_password and @.publisher_password (if you specify this)
> parameters.
> --
> Hilary Cotter
> Looking for a book on SQL Server replication?
> http://www.nwsu.com/0974973602.html
>
> "Ryan McFall" <mcfall@.hope.edu> wrote in message
> news:%23bCSNfdhEHA.644@.tk2msftngp13.phx.gbl...
> anywhere.
> subscription.
> script
correctly.[vbcol=seagreen]
> because
distributor[vbcol=seagreen]
mode,[vbcol=seagreen]
characters
> as
> with
> is,
> any
>

Monday, March 19, 2012

Creating SQL script to upgrade database

Hi,
I am in a process of upgrading database. I am using SQL script generated by
enterprise manager, which is read by executed by VB in windows installer
project.
It sets up the entire database only after dropping all tables.
I need each and every table to be checked if it already exists, it should
skip the creation of that table. If that table does not exist, only then it
should create that table.
'Generate SQL script' toll of Enterprise managaer gives just 2 options, if
you donot select DROP objects option, it tries to create all tables without
checking of their existence. If you do select DROP objects option, It drop
each table before it creates new one(loss of data).
Is there an option to avoid this situation ?
Means, any way to create a SQL script which checks wheather the table
exists, If it exists, it does nnot try to create it, otherwise it creates the
table.
Thnx
"BONTZ" <BONTZ@.discussions.microsoft.com> wrote in message
news:6670BE8F-7370-422F-98DB-043DCA3511AA@.microsoft.com...
> I am in a process of upgrading database. I am using SQL script generated
by
> enterprise manager, which is read by executed by VB in windows installer
> project.
> It sets up the entire database only after dropping all tables.
> I need each and every table to be checked if it already exists, it
should
> skip the creation of that table. If that table does not exist, only then
it
> should create that table.
> 'Generate SQL script' toll of Enterprise managaer gives just 2 options,
if
> you donot select DROP objects option, it tries to create all tables
without
> checking of their existence. If you do select DROP objects option, It drop
> each table before it creates new one(loss of data).
> Is there an option to avoid this situation ?
> Means, any way to create a SQL script which checks wheather the table
> exists, If it exists, it does nnot try to create it, otherwise it creates
the
> table.
Without writing the additional code to validate the tables, the CREATE TABLE
statements will simply fail for existing tables -- perhaps just ignore the
errors for those tables?
Steve
|||Hi Steve,
Thnx for the response.
I can ignore the errros.. but I am not running script through query
analyzer. As mentioned before, I am running this script through windows
installer program, which rollsback the installation of my application in case
of any error.
I was wondering that there should be an option provided by enterprise
manager which just checks weather table is already present before creating
one.
Regards
"Steve Thompson" wrote:

> "BONTZ" <BONTZ@.discussions.microsoft.com> wrote in message
> news:6670BE8F-7370-422F-98DB-043DCA3511AA@.microsoft.com...
> by
> should
> it
> if
> without
> the
> Without writing the additional code to validate the tables, the CREATE TABLE
> statements will simply fail for existing tables -- perhaps just ignore the
> errors for those tables?
> Steve
>
>
|||Hi,
You could add your own logic, if you use the script wizard to create the
table create and table drop statements -- check out the way the logic
qualifies whether the table exists before the DROP statement is run.
It will require additional coding, but a possible way to enhance your
script.
Steve
"BONTZ" <BONTZ@.discussions.microsoft.com> wrote in message
news:4332D573-F257-425D-8E80-AADBACAD95B4@.microsoft.com...
> Hi Steve,
> Thnx for the response.
> I can ignore the errros.. but I am not running script through query
> analyzer. As mentioned before, I am running this script through windows
> installer program, which rollsback the installation of my application in
case[vbcol=seagreen]
> of any error.
> I was wondering that there should be an option provided by enterprise
> manager which just checks weather table is already present before creating
> one.
> Regards
>
> "Steve Thompson" wrote:
generated[vbcol=seagreen]
installer[vbcol=seagreen]
then[vbcol=seagreen]
options,[vbcol=seagreen]
drop[vbcol=seagreen]
creates[vbcol=seagreen]
TABLE[vbcol=seagreen]
the[vbcol=seagreen]

Friday, February 24, 2012

Creating multilple tables at once

I had a SQL db that i copied all the tables into excel and it generated the quereies in order to create those tables....Is there anyway i could excute all those table creations at once or would it be easier to just write an application that does that for me?i am a little confused on what you are asking. That said if you have generated several CREATE TABLE scripts and your question here is can you compile them all into one big script and execute it to recreate all the tables at once, the answer is YES you can.|||How i do it is I open the Query ananlyzer and input the CREATE TABLE query I see it say the command has excuted succesfully but when does the actual table show up in the SQL server? does it have automatically or do i need to do some eles to actually create the table? How would i go about creating the create table script?|||

since you are using the term "Query Analyzer" I will presume that you are using SQL 2000...

In Query Analyzer you need to display the object explorer. If memory servesI think it was View/Object Explorer but regardless its in the main menu somewhere. Once you have object explorer displayed explore down to an individual table (you may be able to select multiple again its been a while) and select Tasks/Generate Script. Also in Enterprise Mgr. I believe you can perform the equivilent in Enterprise Mgr. (but i seem to recall thoughts that I couldnt so dunno for sure on that). Overall its a VERY EASY PROCESS.

Then open up Query Analyzer, select open file/query, browse to the .sql file you created previously and a new query window with the script's contents will be shown. Hit ctrl & F5 to syntax check it (just a habit of mine personally) and then hit F5 again to execute it. Now via Enterprsie Mgr. and Query Analyzer Object Explorer you should see your new tables. You can interact with the new tables via TSQL Queries or via the GUI in Enterprise Mgr.

Derek

Tuesday, February 14, 2012

Creating DB from scripts

I'm using an integration project to recreate a db as needed from all the scripts i've previously generated. I'm encountering an error when the tables get built in the wrong order because of foreign key constraints. Does anyone know of a way to programmatically execute the scripts of sql tables that don't violate the constraints; so after, I can execute the other table create scripts? Any help or guidance in any way would be appreciated.

I think the SMO alias may be better for you, as SMO has at least the ability to generate scripts taking account of dependencies. See the SMO forum here: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=88&SiteID=1

Donald Farmer

|||Thanks. I will take a look.