Showing posts with label created. Show all posts
Showing posts with label created. Show all posts

Friday, March 30, 2012

How to Execute a SQL (.sql) script from within VB?

Hello,

I am trying to figure out the best way to make VB6 execute an auto-generated .SQL file from SQL Server 2000.

SQL Server 2000 has created a script (about 1000 lines long), creating views and SPs, and I need to execute said script from a VB client application. Similar to the effect of pasting it into the Query Analyser, only automated.

Anyone have a suggestion (besides reformatting evey like and hard-coding it?)

Thanks a ton!read it into a string, and execute it as normal.|||You can read the SQL into a string and give it to a SqlCommand class for ExecuteNonQuery.

One tip: the "GO" batch delimiter is not T-SQL, it is a signal to Query Analyzer. Many script generation tools will place the "GO" delimiter into script files to tell QA where to split up the commands. You'll need to parse the script and execute individual batches as you encounter GO batch delimiters.sql

How to execute a Package?

Hallo


I created my first Package and i am not able to deploy it in my SQL server.

I created a Development Utility and in the OutputPath i got a *.dtsx and a *.SSISDevelopmentManifest file.
When i run the packaage (*.dtsx) it works but when i try to install the package with *.SSISDevelopmentManifest it just genereates a folder in the selected Folder
(...\Microsoft SQL Server\90\DTS\Packages\) and no more.

What am i missing?

All the "Deployment" does is copy the *.dtsx files to the file system or MSDB on the target SQL server. You apparently selected "file system". It did exactly what it was suppose do.

Now you need to connect to the "Integration Services" on the server and look under "File System" and you will see the SSIS packages.|||

Hi soanfu,

When using the Deployment Utility, a directory is created in the Microsoft SQL Server\90\DTS\Packages\ folder. This happens regardless of where your package gets deployed. If the package gets deployed to the file system, the dtsx file will be copied into this directory. If you deploy to SQL Server, the directory is created but remains empty.

As someone else pointed out, connecting to the Integration Services instance will allow you to view all packages deployed to a server - both file system and SQL Server. To connect, open SQL Server Management Services. In the Object Explorer, click the Connect button. Select Integration Services and log in. You should be able to view packages stored to the SQL Server under the Stored Packages\MSDB folder.

Hope this helps,
Andy

|||

Thanks for the tip!

I didn’t know that there is a “Integration Services".

But know I have one more question.

In “Sql Server 2000” we could program the execution of DTS Packages with the option Tasks. How can I do it in SQL Server 2005?

|||You mean, to schedule it? You could use SQL Server Agent for that.

How to execute a DTS Via a stored procedure

Hi I have created a DTS package, it runs well, but i would like to execute it in a storeprocedure

Is this possible and if so where do i start from, I have looked all over for it tho every where i look creates a DTS from a store procedure.

I need desperate help

Thanks in advanvcehere is an excellent solution for you

http://p2p.wrox.com/topic.asp?TOPIC_ID=16647

Wednesday, March 28, 2012

How to estimate SQL database growth when new fields are added?

I need help regarding calculation of database size growth. Here is my
query:
Q1 We have created two SQL databases, databaseA and databaseB; they are
mirror images of a databaseC which is a non - SQL database.
DatabaseB has been altered to accomodate 3-4 new fields. We need to
estimate how much databaseB grew by. Please note that number of rows
and tables have remained same for both databaseB and databaseC. What
would be the best estimation technique?
We tried database size, in properties but results are very weird.
Any suggestion would be highly appreciated.
Thank you,
Anjali
Use Windows Explorer, and compare DatabaseA files with DatabaseB files. The
File size difference (reported by the OS) should be a matter of subtraction.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf
"Anjali" <anjali.bisht@.gmail.com> wrote in message
news:1162533985.274091.33370@.k70g2000cwa.googlegro ups.com...
>I need help regarding calculation of database size growth. Here is my
> query:
> Q1 We have created two SQL databases, databaseA and databaseB; they are
> mirror images of a databaseC which is a non - SQL database.
> DatabaseB has been altered to accomodate 3-4 new fields. We need to
> estimate how much databaseB grew by. Please note that number of rows
> and tables have remained same for both databaseB and databaseC. What
> would be the best estimation technique?
>
> We tried database size, in properties but results are very weird.
> Any suggestion would be highly appreciated.
> Thank you,
> Anjali
>
|||I am not sure i can see SQL database in windows explorer. I have
already checked database sizes through SQL enterprise manager, but i am
not satisfied with results.
Is there any other solution?
Arnie Rowland wrote:[vbcol=seagreen]
> Use Windows Explorer, and compare DatabaseA files with DatabaseB files. The
> File size difference (reported by the OS) should be a matter of subtraction.
> --
> Arnie Rowland, Ph.D.
> Westwood Consulting, Inc
> Most good judgment comes from experience.
> Most experience comes from bad judgment.
> - Anonymous
> You can't help someone get up a hill without getting a little closer to the
> top yourself.
> - H. Norman Schwarzkopf
>
> "Anjali" <anjali.bisht@.gmail.com> wrote in message
> news:1162533985.274091.33370@.k70g2000cwa.googlegro ups.com...
|||Of course you can see the database files using Windows Explorer. Unless you
don't have permissions to the OS level of the server. IF that is the
situation, then ask your admin for assistance.
You can calculate the 'estimated' size increase by adding the datatype
storage requirements for the four new fields, and multiplying that by the
total number of rows in the table. If any of the four new columns are
indexed, the effect of indexing is not included.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf
"Anjali" <anjali.bisht@.gmail.com> wrote in message
news:1162550620.309751.37790@.m7g2000cwm.googlegrou ps.com...
>I am not sure i can see SQL database in windows explorer. I have
> already checked database sizes through SQL enterprise manager, but i am
> not satisfied with results.
> Is there any other solution?
> Arnie Rowland wrote:
>

How to estimate SQL database growth when new fields are added?

I need help regarding calculation of database size growth. Here is my
query:
Q1 We have created two SQL databases, databaseA and databaseB; they are
mirror images of a databaseC which is a non - SQL database.
DatabaseB has been altered to accomodate 3-4 new fields. We need to
estimate how much databaseB grew by. Please note that number of rows
and tables have remained same for both databaseB and databaseC. What
would be the best estimation technique?
We tried database size, in properties but results are very weird.
Any suggestion would be highly appreciated.
Thank you,
AnjaliUse Windows Explorer, and compare DatabaseA files with DatabaseB files. The
File size difference (reported by the OS) should be a matter of subtraction.
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf
"Anjali" <anjali.bisht@.gmail.com> wrote in message
news:1162533985.274091.33370@.k70g2000cwa.googlegroups.com...
>I need help regarding calculation of database size growth. Here is my
> query:
> Q1 We have created two SQL databases, databaseA and databaseB; they are
> mirror images of a databaseC which is a non - SQL database.
> DatabaseB has been altered to accomodate 3-4 new fields. We need to
> estimate how much databaseB grew by. Please note that number of rows
> and tables have remained same for both databaseB and databaseC. What
> would be the best estimation technique?
>
> We tried database size, in properties but results are very weird.
> Any suggestion would be highly appreciated.
> Thank you,
> Anjali
>|||I am not sure i can see SQL database in windows explorer. I have
already checked database sizes through SQL enterprise manager, but i am
not satisfied with results.
Is there any other solution?
Arnie Rowland wrote:
> Use Windows Explorer, and compare DatabaseA files with DatabaseB files. The
> File size difference (reported by the OS) should be a matter of subtraction.
> --
> Arnie Rowland, Ph.D.
> Westwood Consulting, Inc
> Most good judgment comes from experience.
> Most experience comes from bad judgment.
> - Anonymous
> You can't help someone get up a hill without getting a little closer to the
> top yourself.
> - H. Norman Schwarzkopf
>
> "Anjali" <anjali.bisht@.gmail.com> wrote in message
> news:1162533985.274091.33370@.k70g2000cwa.googlegroups.com...
> >I need help regarding calculation of database size growth. Here is my
> > query:
> >
> > Q1 We have created two SQL databases, databaseA and databaseB; they are
> > mirror images of a databaseC which is a non - SQL database.
> >
> > DatabaseB has been altered to accomodate 3-4 new fields. We need to
> > estimate how much databaseB grew by. Please note that number of rows
> > and tables have remained same for both databaseB and databaseC. What
> > would be the best estimation technique?
> >
> >
> > We tried database size, in properties but results are very weird.
> >
> > Any suggestion would be highly appreciated.
> > Thank you,
> > Anjali
> >|||Of course you can see the database files using Windows Explorer. Unless you
don't have permissions to the OS level of the server. IF that is the
situation, then ask your admin for assistance.
You can calculate the 'estimated' size increase by adding the datatype
storage requirements for the four new fields, and multiplying that by the
total number of rows in the table. If any of the four new columns are
indexed, the effect of indexing is not included.
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf
"Anjali" <anjali.bisht@.gmail.com> wrote in message
news:1162550620.309751.37790@.m7g2000cwm.googlegroups.com...
>I am not sure i can see SQL database in windows explorer. I have
> already checked database sizes through SQL enterprise manager, but i am
> not satisfied with results.
> Is there any other solution?
> Arnie Rowland wrote:
>> Use Windows Explorer, and compare DatabaseA files with DatabaseB files.
>> The
>> File size difference (reported by the OS) should be a matter of
>> subtraction.
>> --
>> Arnie Rowland, Ph.D.
>> Westwood Consulting, Inc
>> Most good judgment comes from experience.
>> Most experience comes from bad judgment.
>> - Anonymous
>> You can't help someone get up a hill without getting a little closer to
>> the
>> top yourself.
>> - H. Norman Schwarzkopf
>>
>> "Anjali" <anjali.bisht@.gmail.com> wrote in message
>> news:1162533985.274091.33370@.k70g2000cwa.googlegroups.com...
>> >I need help regarding calculation of database size growth. Here is my
>> > query:
>> >
>> > Q1 We have created two SQL databases, databaseA and databaseB; they are
>> > mirror images of a databaseC which is a non - SQL database.
>> >
>> > DatabaseB has been altered to accomodate 3-4 new fields. We need to
>> > estimate how much databaseB grew by. Please note that number of rows
>> > and tables have remained same for both databaseB and databaseC. What
>> > would be the best estimation technique?
>> >
>> >
>> > We tried database size, in properties but results are very weird.
>> >
>> > Any suggestion would be highly appreciated.
>> > Thank you,
>> > Anjali
>> >
>sql

How to estimate SQL database growth when new fields are added?

I need help regarding calculation of database size growth. Here is my
query:
Q1 We have created two SQL databases, databaseA and databaseB; they are
mirror images of a databaseC which is a non - SQL database.
DatabaseB has been altered to accomodate 3-4 new fields. We need to
estimate how much databaseB grew by. Please note that number of rows
and tables have remained same for both databaseB and databaseC. What
would be the best estimation technique?
We tried database size, in properties but results are very weird.
Any suggestion would be highly appreciated.
Thank you,
AnjaliUse Windows Explorer, and compare DatabaseA files with DatabaseB files. The
File size difference (reported by the OS) should be a matter of subtraction.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf
"Anjali" <anjali.bisht@.gmail.com> wrote in message
news:1162533985.274091.33370@.k70g2000cwa.googlegroups.com...
>I need help regarding calculation of database size growth. Here is my
> query:
> Q1 We have created two SQL databases, databaseA and databaseB; they are
> mirror images of a databaseC which is a non - SQL database.
> DatabaseB has been altered to accomodate 3-4 new fields. We need to
> estimate how much databaseB grew by. Please note that number of rows
> and tables have remained same for both databaseB and databaseC. What
> would be the best estimation technique?
>
> We tried database size, in properties but results are very weird.
> Any suggestion would be highly appreciated.
> Thank you,
> Anjali
>|||I am not sure i can see SQL database in windows explorer. I have
already checked database sizes through SQL enterprise manager, but i am
not satisfied with results.
Is there any other solution?
Arnie Rowland wrote:[vbcol=seagreen]
> Use Windows Explorer, and compare DatabaseA files with DatabaseB files. Th
e
> File size difference (reported by the OS) should be a matter of subtractio
n.
> --
> Arnie Rowland, Ph.D.
> Westwood Consulting, Inc
> Most good judgment comes from experience.
> Most experience comes from bad judgment.
> - Anonymous
> You can't help someone get up a hill without getting a little closer to th
e
> top yourself.
> - H. Norman Schwarzkopf
>
> "Anjali" <anjali.bisht@.gmail.com> wrote in message
> news:1162533985.274091.33370@.k70g2000cwa.googlegroups.com...|||Of course you can see the database files using Windows Explorer. Unless you
don't have permissions to the OS level of the server. IF that is the
situation, then ask your admin for assistance.
You can calculate the 'estimated' size increase by adding the datatype
storage requirements for the four new fields, and multiplying that by the
total number of rows in the table. If any of the four new columns are
indexed, the effect of indexing is not included.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf
"Anjali" <anjali.bisht@.gmail.com> wrote in message
news:1162550620.309751.37790@.m7g2000cwm.googlegroups.com...
>I am not sure i can see SQL database in windows explorer. I have
> already checked database sizes through SQL enterprise manager, but i am
> not satisfied with results.
> Is there any other solution?
> Arnie Rowland wrote:
>

How to enter manually a "uniqueIdentifier" type value

I created a DB and a table in Visual Studio .NET 2003. For one of the column
I choose the data type uniqueidentifier.
How can I add manually a unique ID value in the table value editor?
OK, figured it out: select newID() as the default value.
"Frank" <someone@.nospam.com> wrote in message
news:c5f6j4$dpe$1@.news.mch.sbs.de...
> I created a DB and a table in Visual Studio .NET 2003. For one of the
column
> I choose the data type uniqueidentifier.
> How can I add manually a unique ID value in the table value editor?
>

Wednesday, March 21, 2012

How to embed Activex contol in SSRS

How to embed Activex contol in SSRS. I have created one custom library in VB.NET and tried to reference and previewed (Report -> Report Properties-> Reference), but I got following errors. Same library is working fine for other .NET applications. Is there any limitations to use .dll in SSRS, please let me know
1) "Error while loading code module:"
2) "Error in class instance declaration"
Any chance??

Monday, March 19, 2012

How to edit textbox or a cell of table?

Hi everybody!
I've created a report in reporting services and in it i need to have a
dynamic textbox.
Let me describe more.I have two reports ,in first report i have
manegers' names .After that users see first report and manegers'
informations for example their names and saleries , they want to
select manegers on base for example their saleries ,i mean the user
must see informations then decide and select manegers who their
employees will be shown in second report ,in this case i need a
textbox that the user can write Yes or No in it,or checkbox for
multiple select .
After that users select their manegers they can see manegers'
employees in second report.
I need a textbox that has two values (Yes and No) and these values
must be shown in textbox in preview mode to select by users or user
can select Yes or No or checkbox.
Can anybody help me?
ShimaSwhy not just create one report that groups on the managers names and when
the name is clicked the details are shown. This functionality is built in
and easy to do.
another option is to add link on the managers name and when clicked open the
second report by passing the manager's name as a parameter. you won't be
able to do multiple choices though.
<shima.seifolahi@.gmail.com> wrote in message
news:1193114815.518228.133770@.t8g2000prg.googlegroups.com...
> Hi everybody!
> I've created a report in reporting services and in it i need to have a
> dynamic textbox.
> Let me describe more.I have two reports ,in first report i have
> manegers' names .After that users see first report and manegers'
> informations for example their names and saleries , they want to
> select manegers on base for example their saleries ,i mean the user
> must see informations then decide and select manegers who their
> employees will be shown in second report ,in this case i need a
> textbox that the user can write Yes or No in it,or checkbox for
> multiple select .
> After that users select their manegers they can see manegers'
> employees in second report.
> I need a textbox that has two values (Yes and No) and these values
> must be shown in textbox in preview mode to select by users or user
> can select Yes or No or checkbox.
> Can anybody help me?
> ShimaS
>|||I did it ,but i need to select more than one prson in first report,
for one person i don't have any problem
Thanks

How to edit a asp.net2.0/C# project in VS2005, Plz HELP

hi all,

I created a new sql server 2005 database name wsat_demo in the

(lESSQL1)\sql2k5 enterprise server

in the default website properties i added a connection string named WSAT1 to wsat_demo database using aspnet_user account with SA priveledge

i modified the machine.config to use WSAT1 connection string

Then i run the WSAT (website admin tools) to create users.

this error appears. "Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'. "

i've tried attaching the database created by the asp.net project located at app_data folder named it App_data1 database

do the same configuration as stated above. Viola! the WSAT connects to it.

After comprehensive investigation, App_data1 database shows that it contains many security objects builtin to it by asp.net 2 application.

QUESTION: How can I have WSAT_demo database to have the same object as App_data1 given the fact that my connection is enjoying SA priviledge?

thanks,

joeydj

Pareng joey...musta na buhay natin?

Are you creating a database that will store user profiles? If you are, you might wanna start by creating a blank SQL Server database. Then, run the aspnet_regsql.exe and point to this blank database you just created. This is a wizard that creates all these database objects in SQL Server(whether it's 2000 or 2005). Then you can point your ASP.NET 2.0 web app to this database in your web.config. But before you can do this, make sure you override the settings in th machine.config. For a complete step-by-step guide on this, check out Scott Guthrie's blog as this was my guide when I was working on a similar task using the Beta 2 version of Visual Studio 2005

|||

okay lang. sounds like i'm at the

msforums it used to be msdn.ph

running the aspnet_regsql.exe is just like attaching the database

from the app_data on the remote server

|||

Hi,

How can i run or edit my ASP.NET 2.0/C# project in VS2005. I have source code files (including database) but it doesn't have .sln file. Please guide me how can i edit or run this in VS2005

How to dynamically process a Model in a Web App

Hi,

I am a novice at Data Mining realm on SQL Server.

Scenario:

I have created a Time Series model and deployed it into SQL Server. I hope users can see forecast based on the up-to-date data residing in data source rather than the old ones used to train the model. In a addition, the interface provided for users is a .aspx.

Problems:

What ADO APIs should I exploit to dynamically process the model, perform the forecast and retrieve the results.

Any help would be appreciated.

Best Wishes,

Ricky.

You would likely use ADOMD.NET, not ADO.NEt, but the results would essentially be the same. You would likely want to create models on the fly for this solution, much the same way we do for the Excel addins. You can download the addins and use the trace mechanism to see what commands we send to the server.

Essentially, you want to use CREATE SESSION MINING MODEL, INSERT INTO (you can use an input rowset, or an openquery if your data is in a database), and then SELECT PredictTimeSeries(...) to get the forecast.

Using a session model will cause the model to automatically be deleted on disconnection. Note that you will have to turn on the server property to allow session models.

|||

Thanks a lot, Jamie.

Could you give a tutorial or exmaple code to see the deatils?

Regards,

Ricky.

|||The sample here (http://www.sqlserverdatamining.com/DMCommunity/LiveSamples/1866.aspx) creates and trains models dynamically|||

Many Thanks, Jamie

Regards,

Ricky.

|||

mr jamie...

this link seems to be dead

please send in the link again

|||

http://www.sqlserverdatamining.com/DMCommunity/LiveSamples/1866.aspx

|||

hi jamie..

could u look into this thread plz...

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1449395&SiteID=1

;m stuck at thiz prb...

i've reinstalled the dm viewer controls.......

now here is wat i read in the readme file as to how to use the dm viewer controls:

In the Winform designer, right click on the Toolbox and select 'Choose Items...' menu item. Hit the Brows button and select file 'Microsoft.AnalysisServices.Viewers.dll'. Hit the OK button to add all the viewer controls to your toolbox.

the prob is tat i can't find this file:'Microsoft.AnalysisServices.Viewers.dll'

do u think i've gone wrong somewhr in the installation of the viewer controls?

or is there somethin else that i must do?

Monday, March 12, 2012

How to drop Primary key by specifying column only?

I checked column from xsd file which created from DataBase.

And before installing my application I will check any column in destination base whether have complete column or not.

And if there is any column which is not wanted column(not same as xsd structure)

I will delete it by creating sql command as follow "ALTER TABLE tableName DROP COLUMN column1, column2, ....."

and Execute it by program initialization.

So

I need delete it by run-time

However some column may be Primary Key with any reason

That's why I can't delete them by simple command

I expect to delete them by specific column instead of specific constraint name which is not sure name.

Please advise me...

I don't think you can do it by just specifying a column but you can do it this way:

To get the name of the primary key:

SELECT constraint_name
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE (TABLE_NAME = 'TestTable') AND (CONSTRAINT_TYPE = 'PRIMARY KEY')

To drop the primary key:

ALTER TABLE TestTable
DROP CONSTRAINT PK_TestTable

|||

Thanks a lot

:D

How to DROP DEFAULT constraint?

We initially created a table (SQL Server 2000) having a column with a
DEFAULT value of 0. We want to drop the column, but we cannot until the
DEFAULT constraint is removed. Documentation indicates we should be able to
use the command:
"ALTER TABLE MyTable ALTER COLUMN MyColumn DROP DEFAULT"
but it gives us a syntax error.
Other documentation indicates the "DROP DEFAULT" option is deprecated and we
shouldn't use it.
Can anyone tell me how to do this?Hi
ALTER TABLE...DROP CONSTRAINT......
"Meade Swenson" <mswenson@.e-specs.com> wrote in message
news:u5Q2lzDoGHA.1244@.TK2MSFTNGP05.phx.gbl...
> We initially created a table (SQL Server 2000) having a column with a
> DEFAULT value of 0. We want to drop the column, but we cannot until the
> DEFAULT constraint is removed. Documentation indicates we should be able
> to use the command:
> "ALTER TABLE MyTable ALTER COLUMN MyColumn DROP DEFAULT"
> but it gives us a syntax error.
> Other documentation indicates the "DROP DEFAULT" option is deprecated and
> we shouldn't use it.
> Can anyone tell me how to do this?
>|||Thanks Uri...
Unfortunately, when the DEFAULT contraint was added, it wasn't given a name:
"ALTER TABLE MyTable ADD MyColumn INT DEFAULT 0"
Apparently, the system created its own named constraint which I found in
sysobjects. Am I stuck querying the sysobjects table for the name of the
constraint (based on the table/column names) and then using the retrieved
name in the DROP CONSTRAINT clause?
...mcs
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:uvG7W4DoGHA.4124@.TK2MSFTNGP03.phx.gbl...
> Hi
> ALTER TABLE...DROP CONSTRAINT......
> "Meade Swenson" <mswenson@.e-specs.com> wrote in message
> news:u5Q2lzDoGHA.1244@.TK2MSFTNGP05.phx.gbl...
>> We initially created a table (SQL Server 2000) having a column with a
>> DEFAULT value of 0. We want to drop the column, but we cannot until the
>> DEFAULT constraint is removed. Documentation indicates we should be able
>> to use the command:
>> "ALTER TABLE MyTable ALTER COLUMN MyColumn DROP DEFAULT"
>> but it gives us a syntax error.
>> Other documentation indicates the "DROP DEFAULT" option is deprecated and
>> we shouldn't use it.
>> Can anyone tell me how to do this?
>|||Hi
Yes , run sp_helpconstraint 'tablename'
"Meade Swenson" <mswenson@.e-specs.com> wrote in message
news:OFRZtAEoGHA.4616@.TK2MSFTNGP05.phx.gbl...
> Thanks Uri...
> Unfortunately, when the DEFAULT contraint was added, it wasn't given a
> name:
> "ALTER TABLE MyTable ADD MyColumn INT DEFAULT 0"
> Apparently, the system created its own named constraint which I found in
> sysobjects. Am I stuck querying the sysobjects table for the name of the
> constraint (based on the table/column names) and then using the retrieved
> name in the DROP CONSTRAINT clause?
> ...mcs
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:uvG7W4DoGHA.4124@.TK2MSFTNGP03.phx.gbl...
>> Hi
>> ALTER TABLE...DROP CONSTRAINT......
>> "Meade Swenson" <mswenson@.e-specs.com> wrote in message
>> news:u5Q2lzDoGHA.1244@.TK2MSFTNGP05.phx.gbl...
>> We initially created a table (SQL Server 2000) having a column with a
>> DEFAULT value of 0. We want to drop the column, but we cannot until the
>> DEFAULT constraint is removed. Documentation indicates we should be able
>> to use the command:
>> "ALTER TABLE MyTable ALTER COLUMN MyColumn DROP DEFAULT"
>> but it gives us a syntax error.
>> Other documentation indicates the "DROP DEFAULT" option is deprecated
>> and we shouldn't use it.
>> Can anyone tell me how to do this?
>>
>|||Okay, thanks.
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:uWngbCEoGHA.4464@.TK2MSFTNGP04.phx.gbl...
> Hi
> Yes , run sp_helpconstraint 'tablename'
> "Meade Swenson" <mswenson@.e-specs.com> wrote in message
> news:OFRZtAEoGHA.4616@.TK2MSFTNGP05.phx.gbl...
>> Thanks Uri...
>> Unfortunately, when the DEFAULT contraint was added, it wasn't given a
>> name:
>> "ALTER TABLE MyTable ADD MyColumn INT DEFAULT 0"
>> Apparently, the system created its own named constraint which I found in
>> sysobjects. Am I stuck querying the sysobjects table for the name of the
>> constraint (based on the table/column names) and then using the retrieved
>> name in the DROP CONSTRAINT clause?
>> ...mcs
>> "Uri Dimant" <urid@.iscar.co.il> wrote in message
>> news:uvG7W4DoGHA.4124@.TK2MSFTNGP03.phx.gbl...
>> Hi
>> ALTER TABLE...DROP CONSTRAINT......
>> "Meade Swenson" <mswenson@.e-specs.com> wrote in message
>> news:u5Q2lzDoGHA.1244@.TK2MSFTNGP05.phx.gbl...
>> We initially created a table (SQL Server 2000) having a column with a
>> DEFAULT value of 0. We want to drop the column, but we cannot until
>> the DEFAULT constraint is removed. Documentation indicates we should be
>> able to use the command:
>> "ALTER TABLE MyTable ALTER COLUMN MyColumn DROP DEFAULT"
>> but it gives us a syntax error.
>> Other documentation indicates the "DROP DEFAULT" option is deprecated
>> and we shouldn't use it.
>> Can anyone tell me how to do this?
>>
>>
>

Friday, March 9, 2012

How to DROP DEFAULT constraint?

We initially created a table (SQL Server 2000) having a column with a
DEFAULT value of 0. We want to drop the column, but we cannot until the
DEFAULT constraint is removed. Documentation indicates we should be able to
use the command:
"ALTER TABLE MyTable ALTER COLUMN MyColumn DROP DEFAULT"
but it gives us a syntax error.
Other documentation indicates the "DROP DEFAULT" option is deprecated and we
shouldn't use it.
Can anyone tell me how to do this?Hi
ALTER TABLE...DROP CONSTRAINT......
"Meade Swenson" <mswenson@.e-specs.com> wrote in message
news:u5Q2lzDoGHA.1244@.TK2MSFTNGP05.phx.gbl...
> We initially created a table (SQL Server 2000) having a column with a
> DEFAULT value of 0. We want to drop the column, but we cannot until the
> DEFAULT constraint is removed. Documentation indicates we should be able
> to use the command:
> "ALTER TABLE MyTable ALTER COLUMN MyColumn DROP DEFAULT"
> but it gives us a syntax error.
> Other documentation indicates the "DROP DEFAULT" option is deprecated and
> we shouldn't use it.
> Can anyone tell me how to do this?
>|||Thanks Uri...
Unfortunately, when the DEFAULT contraint was added, it wasn't given a name:
"ALTER TABLE MyTable ADD MyColumn INT DEFAULT 0"
Apparently, the system created its own named constraint which I found in
sysobjects. Am I stuck querying the sysobjects table for the name of the
constraint (based on the table/column names) and then using the retrieved
name in the DROP CONSTRAINT clause?
...mcs
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:uvG7W4DoGHA.4124@.TK2MSFTNGP03.phx.gbl...
> Hi
> ALTER TABLE...DROP CONSTRAINT......
> "Meade Swenson" <mswenson@.e-specs.com> wrote in message
> news:u5Q2lzDoGHA.1244@.TK2MSFTNGP05.phx.gbl...
>|||Hi
Yes , run sp_helpconstraint 'tablename'
"Meade Swenson" <mswenson@.e-specs.com> wrote in message
news:OFRZtAEoGHA.4616@.TK2MSFTNGP05.phx.gbl...
> Thanks Uri...
> Unfortunately, when the DEFAULT contraint was added, it wasn't given a
> name:
> "ALTER TABLE MyTable ADD MyColumn INT DEFAULT 0"
> Apparently, the system created its own named constraint which I found in
> sysobjects. Am I stuck querying the sysobjects table for the name of the
> constraint (based on the table/column names) and then using the retrieved
> name in the DROP CONSTRAINT clause?
> ...mcs
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:uvG7W4DoGHA.4124@.TK2MSFTNGP03.phx.gbl...
>|||Okay, thanks.
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:uWngbCEoGHA.4464@.TK2MSFTNGP04.phx.gbl...
> Hi
> Yes , run sp_helpconstraint 'tablename'
> "Meade Swenson" <mswenson@.e-specs.com> wrote in message
> news:OFRZtAEoGHA.4616@.TK2MSFTNGP05.phx.gbl...
>

how to drop all keys & indexes

I'm trying to drop all indexes and primary keys so that i can rebuild them
(from a script created from same database on another server).

when i go to the 'generate sql scripts', it has the ability to drop or
generate all
tables. it also has the ability to generate all keys only. but i cant find
a way
to drop all of these keys...

any ideas?

tia
woody rao"Woody Rao" <nvwoody@.dreamscape.com> wrote in message
news:10b9lq618pmaoec@.corp.supernews.com...
> I'm trying to drop all indexes and primary keys so that i can rebuild them
> (from a script created from same database on another server).
> when i go to the 'generate sql scripts', it has the ability to drop or
> generate all
> tables. it also has the ability to generate all keys only. but i cant
find
> a way
> to drop all of these keys...
> any ideas?
> tia
> woody rao

One way is to copy and paste the result of a query like this one (assuming
all tables are owned by dbo):

select 'alter table dbo.'+ TABLE_NAME + ' drop constraint ' +
CONSTRAINT_NAME
from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
where CONSTRAINT_TYPE in ('PRIMARY KEY', 'FOREIGN KEY')

This can be automated with a cursor and EXEC() if necessary, although you
may find it easier to look at a database comparison tool which will build
migration/synchronization scripts for you.

Simon

How to Drop a user from a database who owns a dbo schema and is the dbo

SQL Server 2005 Developer Edition:

I can't figure out how to drop a user from a database who is the dbo on a database.

I thought if I created another user to become the new dbo I could then drop the old dbo, but when I try that I get an error saying the user can't be dropped because it owns a dbo schema. Now I have two dbo users I can't get rid of...

How do I get rid of the one I don't want...

Try the following (while logged as a member of sysadmin, other than users you are working on):

1. Create a login
2. While in the context of a database you are changing users for, execute sp_changedbowner 'your_newly_created_login' (see Books Online for detailed help on this SP)
3. Then you should be able to drop users and logins who used to be dbowners

Please let me know if this worked for you or if you need further help.

HTH,
Boris.

|||

Boris B wrote:

Try the following (while logged as a member of sysadmin, other than users you are working on):

1. Create a login
2. While in the context of a database you are changing users for, execute sp_changedbowner 'your_newly_created_login' (see Books Online for detailed help on this SP)
3. Then you should be able to drop users and logins who used to be dbowners

Please let me know if this worked for you or if you need further help.

HTH,
Boris.

Thank you, Boris. I will try that tomorrow and let you know what happens.

How to drop a user defined database role in 2005?

Using Studio, I created a user defined database role but I can not delete it because

"TITLE: Microsoft SQL Server Management Studio

Drop failed for DatabaseRole 'test1'. (Microsoft.SqlServer.Smo)

ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15138)

I am quite annoyed because the "owned schema" is db_owner, which can not be unselected. Quite an innovation. How do I drop this relationship?

i think the DB_Owner schema is owned by this role

run this statement to see the schema and owner ... check whether this role is the owner of any schema

SELECT s.name SchemaName, d.name SchemaOwnerName FROM sys.schemas s INNER JOIN sys.database_principals d ON s.principal_id= d.principal_id

if this role owner of DB_Owner Schema run the below statment to transfer the owner ship..

ALTER AUTHORIZATION ON SCHEMA::[db_owner] TO [db_owner]

Drop role test1

Madhu

|||Nice and simple. Does the trick. Thanks Madhu.

Cheers,

Sameer.

How to drop a user defined database role in 2005?

Using Studio, I created a user defined database role but I can not delete it because

"TITLE: Microsoft SQL Server Management Studio

Drop failed for DatabaseRole 'test1'. (Microsoft.SqlServer.Smo)

ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15138)

I am quite annoyed because the "owned schema" is db_owner, which can not be unselected. Quite an innovation. How do I drop this relationship?

i think the DB_Owner schema is owned by this role

run this statement to see the schema and owner ... check whether this role is the owner of any schema

SELECT s.name SchemaName, d.name SchemaOwnerName FROM sys.schemas s INNER JOIN sys.database_principals d ON s.principal_id= d.principal_id

if this role owner of DB_Owner Schema run the below statment to transfer the owner ship..

ALTER AUTHORIZATION ON SCHEMA::[db_owner] TO [db_owner]

Drop role test1

Madhu

|||Nice and simple. Does the trick. Thanks Madhu.

Cheers,

Sameer.

How to drill down on fields

Hi All ,

I am new to Sql Server and Reporting services ..

I was trying to make a drill down report

I have created Grooup on detail row and set the Visibility with one of the group rows just above ..

But when preview the report I cannot see any data ..

How ever If I Delete the Groups I can see the data ..

Is there anything that I am missing Please help

Did you specify the toggle item ? Otherwise you won′t be able to toggel the hidden rows.

Jens K. Suessmeyer.

http://www.sqlserver2005.de
|||

Hi Jens ,

Thanks for did that and am able to see the data ..

how to download the image or file from the [Blobcontent] as file in sql server 2005?

hi,

i plan to use the database mail to send the mail. i created stored procedure to send the mail to all receipents ,.

Table fields like, profile,Toaddress,Bcc,Ccc,Blbcontents ,filename..subj,msgbody ,etc...,

download the blb & attach with the mail for the particular recepent

.

so., is it possible to download the blobcontent using Query? or any Other function available in Sqlserver 2005?

In order to attach files to an email in Database Mail on SQL Server 2005, the files must be on disk. If you are storing files at blobs (VarBinary or image) in your SQL Server database, you must extract them to disk before attaching them to your mail.

Does that answer your question?

Paul A. Mestemaker II

Program Manager

Microsoft SQL Server Manageability

http://blogs.msdn.com/sqlrem/

|||

thanks Mr.Paul A. Mestemaker,

my question is, Is any system procedure available to download the blob-content in sql server 2005 database itself?

Please let me know ..

any way, myself found the solution, please let me know the procedure is correct

i wrote the clr integrated procedure using c# application

the below steps i have done

1. created the ExportBlob.dll file

2. Created assembly with ExportBlob.dll.

3. Created Procedure to call the Dll file with param.

4. Created ownProcedure to send mail

5. if you want to send mail as Automatically, create new job & set the schedule time to run in sql server agents.

this code is working fine.

Create assembly

==============

USE [master]

Go

/* register the assembly in a SQL Server database using the CREATE ASSEMBLY statement */

CREATE ASSEMBLY ExportBlob

FROM 'D:\Extended_Proc\sp_exportBlob.dll'

WITH PERMISSION_SET = EXTERNAL_ACCESS

GO

GO

/****** Object: StoredProcedure [dbo].[xp_ExportBlob]

CREATE PROCEDURE [dbo].[xp_ExportBlob]

@.ServerName [nvarchar](25),

@.UID [nvarchar](50),

@.Pwd [nvarchar](25),

@.DBName [nvarchar](25),

@.Tbname [nvarchar](50),

@.FldName [nvarchar](100),

@.cndt [nvarchar](max),

@.Exportpath [nvarchar](100)

WITH EXECUTE AS CALLER

AS

EXTERNAL NAME [ExportBlob].[sp_exportBlob].[exportBlob] //

mail send

=========

SET @.DBName=db_name() /* Get & Assign the Current Database Name*/

SET @.Server=@.@.servername

Select @.ListOfAttachFiles='', @.Delimiter=';'

/*Create a Local Dir to save the File*/

set @.ExtractPath='C:\SQLdbmail_attched_files\

DECLARE CursorMailList CURSOR FOR

SELECT [MailID],

[Profile],

left(Subject,255),

[importance],

[MsgTo],

[CopyTo],

[BCCTo],

[Contents],

isnull(HasAttachment,0)

FROM MailTb Where Processed=0 Order by MailID

OPEN CursorMailList

FETCH NEXT FROM CursorMailList INTO @.MailID,@.Profile,@.m_subject,@.m_importance,@.m_Toaddress,@.m_ccaddress,@.m_Bccaddress,@.m_body,@.HasAttachment

WHILE (@.@.FETCH_STATUS = 0)

BEGIN

Select @.ListOfAttachFiles=@.ListOfAttachFiles + @.ExtractPath+Filename+@.Delimiter from Attachments where MailID=@.MailID

SET @.ListOfAttachFiles=left(@.ListOfAttachFiles,len(@.ListOfAttachFiles)-1)

SET @.cndtn='where Datalength(Blobcontents)>0 and MailID='+ convert(VARCHAR,@.MailID,25)

select @.FldNames='Blobcontents,Filename'

/*Download File in the server Dir */

/*passing param to dll , param=servername,UID,PWD,DatabaseName,Tablename,Feildname,wherecndtn,extractDir */

EXEC master..xp_ExportBlob @.Server, 'sa', 'pass', @.DBName, 'Attachments', @.FldNames, @.cndtn, @.ExtractPath

/*Get Missing Attchment Files */

BEGIN TRY

EXECUTE msdb..sp_send_dbmail

@.profile_name = @.Profile

,@.recipients = @.m_Toaddress

,@.copy_recipients = @.m_ccaddress

,@.blind_copy_recipients = @.m_Bccaddress

,@.body = @.m_body

,@.subject = @.m_subject

,@.importance = @.m_importance

,@.file_attachments = @.ListOfAttachFiles /* Eg. D:\mailDownload\filename.ext;c D:\mailDownload\filename2.ext */

,@.mailitem_id = @.mailitemid output

Update MailTb set Processed=1 where MailID=@.MailID /*Update back Mail sent scessfully*/

END TRY /*TRY*/

BEGIN CATCH

SET @.err=1

set @.ErrMsg = @.ErrMsg +'Failed to send Mail with Attachments. SDS MailID ='+convert(varchar,@.MailId,25)

END CATCH /*Catch*/

END /*

FETCH NEXT FROM CursorMailList INTO @.MailID,@.Profile,@.m_subject,@.m_importance,@.m_Toaddress,@.m_ccaddress,@.m_Bccaddress,@.m_body,@.HasAttachment

END /*WHILE*/

-- clean up; close & Deallocate the cursor

CLOSE CursorMailList

DEALLOCATE CursorMailList

c# application {Create library}

====================

using System;

using System.Collections.Generic;

using System.Text;

using System.IO;

using System.Data.SqlClient;

using System.Data.Sql;

using Microsoft.SqlServer.Server;

using System.Data.SqlTypes;

public class sp_exportBlob

{

// Identify that this is a SQL Stored Procedure

[SqlProcedure]

//summary

//FldNames should be BlobContents and Filename with Extension using comma Sepearator.

// [i.e., Fldnames="Blobcontents,Filename+Extension" ]

//

public static void exportBlob(string ServerName, string UID, string Pwd, string DBName, string TbName, string Fldnames, string Cndt, string ExtractPath)

{

SqlConnection sqlconn = new SqlConnection();

SqlDataReader sqlDr;

SqlCommand cmd;

FileStream fs;

BinaryWriter bw;

int Blobsize;

long blob, startIndex;

byte[] outBuffer;

string ExtractFileName = "";

try

{

int IndexBlobContents = 0;

sqlconn.ConnectionString = "Server=" + ServerName + ";UID=" + UID + ";Pwd=" + Pwd + ";Database=" + DBName;

sqlconn.Open();

Blobsize = 1024;// Initalize the BlobSize

cmd = new SqlCommand("SELECT " + Fldnames + " FROM " + TbName + " " + Cndt, sqlconn);

sqlDr = cmd.ExecuteReader();

while (sqlDr.Read())

{

ExtractFileName = ExtractPath + sqlDr[1].ToString();//dirname + filename

startIndex = 0; // Reset the starting byte for the new BLOB.

outBuffer = new byte[Blobsize];

if (File.Exists(@.ExtractFileName))

{

File.Delete(@.ExtractFileName);

}

fs = new FileStream(@.ExtractFileName, FileMode.OpenOrCreate, FileAccess.Write); // Create a file to hold the output.

bw = new BinaryWriter(fs);

blob = sqlDr.GetBytes(IndexBlobContents, startIndex, outBuffer, 0, Blobsize); // Read bytes into outByte[] and retain the number of bytes returned.

while (blob == Blobsize) // Continue while there are bytes beyond the size of the buffer.

{

bw.Write(outBuffer);

bw.Flush();

startIndex += Blobsize;

blob = sqlDr.GetBytes(IndexBlobContents, startIndex, outBuffer, 0, Blobsize);

}

bw.Write(outBuffer, 0, (int)blob);// Write the remaining buffer.

bw.Flush();

bw.Close();

fs.Close();

SqlContext.Pipe.Send("Downloaded successfully in " + ExtractFileName);

}

sqlDr.Close();

}

catch (Exception er)

{

SqlContext.Pipe.Send(er.Message);

}

finally

{

if (sqlconn.State == System.Data.ConnectionState.Open)

{

sqlconn.Close();

}

fs = null;

bw = null;

cmd = null;

sqlDr = null;

sqlconn = null;

}

}

}

|||

Looks pretty cool. I generally don't like to see dynamic SQL, but it seems like it's working for your architecture. Thanks for posting this so the community can benefit :-)

People ask about this quite a bit at conferences... now I have a place to direct them.

Paul A. Mestemaker II

Program Manager

Microsoft SQL Server Manageability

http://blogs.msdn.com/sqlrem/

|||

Hi Raj,

This solution is great. However, I am using a different environment :-

SQL 2005 and Java for this application.

So, i will not be able to use the c# piece of code.

c# application {Create library}

Thanks,