Showing posts with label copy. Show all posts
Showing posts with label copy. Show all posts

Friday, March 30, 2012

Resore .bak to SQL Express

Our vendor has provided us a copy of our data in a .bak files from SQL server. I want to run reports against this data. I have installed Express as well as Server management studio.

I presume I need to restore the .BAK file before I can run any reports? If so how does one do this?

Thanks in advance

In the UI right click on a database and select restore, or review the restore command in Books On Line;

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ra-rz_25rm.asp

Also here is a short example;

RESTORE DATABASE MyNwind
FROM MyNwind_1

Wednesday, March 28, 2012

Resize Filegroups Allocation on restore

Hi, I have a database with about 200Gigs allocated to filegroups and 200Megs data in it presently, and am trying to create a copy of the database on the same server - except I don't have enough diskspace free for another 200Gigs. Is there a way using copy database wizard, or restore that the filegroup allocations can be resized?

Thanks,
Chris

Unfortunately, no.

Backup copies physical blocks and puts them back in the same place that they came from.

Even if your database is only using 200MB out of 200GB, there is no assurance that the 200MB is nicely located in the front of the data files.

Your options are:

If the source database doesn't need to be that big, you can run DBCC SHRINKDATABASE on it and then back it up, or you can temporarily restore the database on a 3rd machine, run SHRINKDATABASE on it, back it up, and take it to your smaller machine.

Friday, March 23, 2012

reset IDENTITY after table data import?

I have a remote DB I am wokring with at present. The DBA has provided me with a non owner LOGIN so I can't copy tables from the live to the staged DB as objects I can only copy tables and data.

The PKEY and IDENTITY COLUMNS get reset to just regular columns on each table. I can restore the PKEY constraint and have come across the DBCC CHECKIDENT to get the new ident value. I just can't figure out how to set a column to be an identity. The ALTER TABLE command isn't having any of it.

I am obviously missing the right bit on Books online

any suggestions?

many thanks

SteveThere isn't any way I know to add the IDENTITY property to an existing column. I'm pretty sure that it must be done at the time of the table creation.

My advice would be to script the table from the production DB, change the script to use IDENTITY, then copy the data from production to your working table.

-PatP

Reset date to first of month

I receive an existing date variable, which I copy to my @.today variable. I
need to reset the day of the month to be the first of the month, leaving all
other aspects of @.today alone.
Any suggestions?
-- simulate the date I get, which I have no control over
declare @.date datetime
set @.date = '02/08/2008'
--assign to my date variable, which I do control
declare @.today datetime
SET @.today = @.date
--the following doesn't work, but it shows what I want to do
SET MONTH(@.today) = 1
SELECT @.today
Thanks
--
RandySET @.today = DATEADD(month,DATEDIFF(month,0,@.date),0)
Steve Kass
Drew University
randy1200 wrote:

>I receive an existing date variable, which I copy to my @.today variable. I
>need to reset the day of the month to be the first of the month, leaving al
l
>other aspects of @.today alone.
>Any suggestions?
>-- simulate the date I get, which I have no control over
>declare @.date datetime
>set @.date = '02/08/2008'
>--assign to my date variable, which I do control
>declare @.today datetime
>SET @.today = @.date
>--the following doesn't work, but it shows what I want to do
>SET MONTH(@.today) = 1
>SELECT @.today
>Thanks
>|||You can try using:
-- simulate the date I get, which I have no control over
declare @.date datetime
set @.date = '02/08/2008'
--assign to my date variable, which I do control
declare @.today datetime
SET @.today = @.date
--If I understood correctly
set @.today = @.today - (DAY(@.today)-1)
SELECT @.today
Let me know if it helps..
"randy1200" wrote:

> I receive an existing date variable, which I copy to my @.today variable. I
> need to reset the day of the month to be the first of the month, leaving a
ll
> other aspects of @.today alone.
> Any suggestions?
> -- simulate the date I get, which I have no control over
> declare @.date datetime
> set @.date = '02/08/2008'
> --assign to my date variable, which I do control
> declare @.today datetime
> SET @.today = @.date
> --the following doesn't work, but it shows what I want to do
> SET MONTH(@.today) = 1
> SELECT @.today
> Thanks
> --
> Randy|||That did it. Many thanks.
--
Randy
"Edgardo Valdez, MCSD, MCDBA" wrote:
> You can try using:
> -- simulate the date I get, which I have no control over
> declare @.date datetime
> set @.date = '02/08/2008'
> --assign to my date variable, which I do control
> declare @.today datetime
> SET @.today = @.date
> --If I understood correctly
> set @.today = @.today - (DAY(@.today)-1)
> SELECT @.today
> Let me know if it helps..
> "randy1200" wrote:
>|||That did it. Many thanks.
--
Randy
"Steve Kass" wrote:

> SET @.today = DATEADD(month,DATEDIFF(month,0,@.date),0)
> Steve Kass
> Drew University
> randy1200 wrote:
>
>|||This one will work for the first date as well:
set @.today = @.today - (case when DAY(@.today) = 1 then 0 else DAY(@.today)-1
end)
"randy1200" wrote:
> That did it. Many thanks.
> --
> Randy
>
> "Edgardo Valdez, MCSD, MCDBA" wrote:
>|||Very . Many thanks again!
--
Randy
"Edgardo Valdez, MCSD, MCDBA" wrote:
> This one will work for the first date as well:
> set @.today = @.today - (case when DAY(@.today) = 1 then 0 else DAY(@.today)-1
> end)
> "randy1200" wrote:
>|||You are very welcome!
"randy1200" wrote:
> Very . Many thanks again!
> --
> Randy
>
> "Edgardo Valdez, MCSD, MCDBA" wrote:
>|||Hi Randy,
Try:
select DATEADD(mm, DATEDIFF(mm,0,@.today), 0)
"DATEDIFF(mm,0,getdate())" calculates the number of months between the curre
nt
date and the date "1900-01-01 00:00:00.000".
Remember date and time variables are stored as the number of milliseconds
since "1900-01-01 00:00:00.000"; this is why you can specify the first datet
ime
expression of the DATEDIFF function as "0."
Now the last function call, DATEADD, adds the number of months between the
current date and '1900-01-01".
By adding the number of months between our pre-determined date '1900-01-01'
and the current date, you are able to arrive at the first day of the current
month.
In addition, the time portion of the calculated date will be "00:00:00.000."

> I receive an existing date variable, which I copy to my @.today
> variable. I
> need to reset the day of the month to be the first of the month,
> leaving all
> other aspects of @.today alone.
> Any suggestions?
> --assign to my date variable, which I do control
> declare @.today datetime
> SET @.today = @.date
> --the following doesn't work, but it shows what I want to do
> SET MONTH(@.today) = 1
> SELECT @.today
> Thanks
>sql

Tuesday, February 21, 2012

ReportViewer-winform

Is there a way to make the data selecatable. For example, a user runs a report and wants to copy the applicationId onto their clipboard so they can use it to search in another application. Currently they have to remember or write down a 9 digit number. Not very user friendly...

I am currently using a data table as the container for the data in my rdl file. Then I use reportviewer for winforms to embed it in our user application.

Thanks

hi mpetanovitch,

You can try this for each TextBox on the Report file.

Suppose there is a table item on the Report file,

Step 1:

At the DesignTime, for each TextBox in the 'Table Details' row :

Do RightClick then go to Properties-->Navigation-->Hyperlink Action

Select 'Jump to URL' and in the following ComboBox type '= "nolink:" & Fields!FieldName.Value'

In the 'Fields!FieldName.Value', replace 'FieldName' with name of the Field containig TextBox.

Step 2:

Put the following line in the ReportViewer1_Load :

this.ReportViewer1.LocalReport.EnableHyperlinks = true;

Step 3:

Add a Handler for the ReportViewer1_HyperLink event like this :

private void ReportViewer1_Hyperlink(object sender, HyperlinkEventArgs e)
{
Uri SelText = new Uri(e.Hyperlink);
if (SelText.Scheme.ToLower() == "nolink")
{
e.Cancel = true;
this.reportViewer1.Find(SelText.AbsolutePath, this.ReportViewer1.CurrentPage);
Clipboard.Clear();
Clipboard.SetText(SelText.AbsolutePath);
}
}

Regards
A. Cheraghi

ReportViewer-winform

Is there a way to make the data selecatable. For example, a user runs a report and wants to copy the applicationId onto their clipboard so they can use it to search in another application. Currently they have to remember or write down a 9 digit number. Not very user friendly...

I am currently using a data table as the container for the data in my rdl file. Then I use reportviewer for winforms to embed it in our user application.

Thanks

hi mpetanovitch,

You can try this for each TextBox on the Report file.

Suppose there is a table item on the Report file,

Step 1:

At the DesignTime, for each TextBox in the 'Table Details' row :

Do RightClick then go to Properties-->Navigation-->Hyperlink Action

Select 'Jump to URL' and in the following ComboBox type '= "nolink:" & Fields!FieldName.Value'

In the 'Fields!FieldName.Value', replace 'FieldName' with name of the Field containig TextBox.

Step 2:

Put the following line in the ReportViewer1_Load :

this.ReportViewer1.LocalReport.EnableHyperlinks = true;

Step 3:

Add a Handler for the ReportViewer1_HyperLink event like this :

private void ReportViewer1_Hyperlink(object sender, HyperlinkEventArgs e)
{
Uri SelText = new Uri(e.Hyperlink);
if (SelText.Scheme.ToLower() == "nolink")
{
e.Cancel = true;
this.reportViewer1.Find(SelText.AbsolutePath, this.ReportViewer1.CurrentPage);
Clipboard.Clear();
Clipboard.SetText(SelText.AbsolutePath);
}
}

Regards
A. Cheraghi