Showing posts with label time. Show all posts
Showing posts with label time. Show all posts

Friday, March 30, 2012

How Can I Restore a Database to Different Files and ...............

Hi,

I have a database that over time has become spread over different files, file groups all of various sizes.

I want to restore this database to a different set of files/filegroups and evenly spread.

It appears that I can only resotore a database to number/of and size of files from which it was backed up..

I want to redistribute a 40GB file, using EMPTY is taking for ever and then eventually fails.

What can I do?

Thanks for your help

Try adding several new data files, then doing a shrink-empty on the big file to get it to be spread out to the new files. If the big data file is your primary data file, that will not work.

Suggestion two is to Rebuild the clustered index for several of your larger tables into the new files. This will move the data.

How can I resolve this database error, in VS 2005?

Every time I try to add a new row to my table, i get this error which i don't now what it means and how i can correct it, could you please advice. i am using VS 2005 and VB Language

**************The error message

"No row was updated.

The data in row 2 was not committed.

Error source:mscorlib.

Error Message: Index was out of range. Must be non-negative and less than the size of the collection.

Parameter name: index"

What code are you using to add the row?

This is the basic VB syntax

Dim myNewRow as DataRow

myNewRow=MyDataTable.NewRow()

|||

Yep. What kind of table? A table in a sql server database, or a datatable, which is a .net class?

|||

i am using sql server database

How can I remove duplicate entries in a sql query?

I have a database being populated by hits to a program on a server.
The problem is each client connection may require a few hits in a 1-2
second time frame. This is resulting in multiple database entries -
all exactly the same, except the event_id field, which is
auto-numbered.

I need a way to query the record w/out duplicates. That is, any
records exactly the same except event_id should only return one record.

Is this possible??

Thank you,

Barrytry this, not tested :-)

SELECT *
FROM table1 a,
(SELECT min(id) FROM table1) AS b
WHERE a.id = b.id

BarrySDCA wrote:
> I have a database being populated by hits to a program on a server.
> The problem is each client connection may require a few hits in a 1-2
> second time frame. This is resulting in multiple database entries -
> all exactly the same, except the event_id field, which is
> auto-numbered.
> I need a way to query the record w/out duplicates. That is, any
> records exactly the same except event_id should only return one record.
> Is this possible??
> Thank you,
> Barry|||hrm...no luck. I ran this:

SELECT * from `playback_log` a,(SELECT min(EVENT_ID) FROM
`playback_log` ) AS b WHERE a.EVENT_ID = b.EVENT_ID

Can you see anything? I appreciate the help a bunch. thank you|||Haven't tested this:

SELECT *
FROM playback_log a
WHERE a.event_id = (select min(event_id) from playback_log b
where a.field1 = b.field1)
;

You will need to list as many fields as need to match the identical rows in the
where clause of the sub-select.

Thomas

BarrySDCA wrote on 03.03.2006 00:33:
> hrm...no luck. I ran this:
>
> SELECT * from `playback_log` a,(SELECT min(EVENT_ID) FROM
> `playback_log` ) AS b WHERE a.EVENT_ID = b.EVENT_ID
>
> Can you see anything? I appreciate the help a bunch. thank you|||"Thomas Kellerer" <WVIJEVPANEHT@.spammotel.com> wrote in message
news:46petmFc69qnU1@.individual.net...
> SELECT *
> FROM playback_log a
> WHERE a.event_id = (select min(event_id) from playback_log b
> where a.field1 = b.field1)

Here's a similar possibility, without using a correlated subquery:

SELECT a.*
FROM playback_log AS a
WHERE a.event_id IN (
SELECT MIN(b.event_id)
FROM playpack_log AS b
GROUP BY b.field1, b.field2, b.field3, ...)

What I've seen missing in the several solutions proposed is any use of GROUP
BY. You'll need to GROUP BY all the fields of the table _except_ for
event_id.

Regards,
Bill K.|||Bill Karwin (bill@.karwin.com) writes:
> "Thomas Kellerer" <WVIJEVPANEHT@.spammotel.com> wrote in message
> news:46petmFc69qnU1@.individual.net...
>> SELECT *
>> FROM playback_log a
>> WHERE a.event_id = (select min(event_id) from playback_log b
>> where a.field1 = b.field1)
> Here's a similar possibility, without using a correlated subquery:
> SELECT a.*
> FROM playback_log AS a
> WHERE a.event_id IN (
> SELECT MIN(b.event_id)
> FROM playpack_log AS b
> GROUP BY b.field1, b.field2, b.field3, ...)
> What I've seen missing in the several solutions proposed is any use of
> GROUP BY. You'll need to GROUP BY all the fields of the table _except_
> for event_id.

One more variation, using a derived table:

SELECT a.*
FROM playback_log AS a
JOIN (SELECT MIN(event_id)
FROM playback_log
GROUP BY field1, field2, ...) AS b ON a.event_id = b.event_id

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||I'm not sure why you need a nested query as others have suggested.

I see two options:

Select Distinct blah1, blah2, [all fields except event_id], blah99
>From LoginTable

or

Select blah1, blah2, [all fields except event_id], blah99
>From LoginTable
Group by blah1, blah2, [all fields except event_id], blah99

if you want an event_id, just for kicks, you could add an aggregator:

Select blah1, blah2, max(event_id), blah99
>From LoginTable
Group by blah1, blah2, [all fields except event_id], blah99|||BarrySDCA wrote:
> I have a database being populated by hits to a program on a server.
> The problem is each client connection may require a few hits in a 1-2
> second time frame. This is resulting in multiple database entries -
> all exactly the same, except the event_id field, which is
> auto-numbered.
> I need a way to query the record w/out duplicates. That is, any
> records exactly the same except event_id should only return one record.
> Is this possible??
> Thank you,
> Barry

Hopefully you found the suggestions on how to filter out the duplicates
helpful.

I just want to point out that this shows the weakness of using a
pseudokey as the primary key of a table. If they really are the same
events, they shouldn't be duplicated.

Actually, I don't think you have duplicate events, since at least some
of the connection hits must have failed or timed out. Otherwise why
were there retries? So they are not really the same. Are you maybe
missing a status or result attribute?

(but the ID field is still a poor crutch for a possibly weak design.)

just some food for thought.
Ed.|||>(but the ID field is still a poor crutch for a possibly weak design.)

hmmmm. i'd prefer to think of it as the table stores ALL hits to the
table, but this particular data consumer only wants to see ONE. The
way I think about it, your natural key would be the composite of all
fields in the table; perhaps "natural", but certainly awkword.

I like figital's solution.|||It's exactly what I'm doing....I'm recording hits to an advertising
engine, before they get to the media server. Some client players hit
more than once before they connect, causing a duplicate entry. I just
want to see it sorted out w/out the duplicates. I have the
distribution server logs for accurate playback reporting, I'm only
interested in seeing cleaned up hits.

I setup code to remove the duplicates, but it's not fool proof. I will
try the suggestions here and let the group know how it goes. Here is a
link to what I'm doing:

http://www.sundiegolive.com/advertising.htm notice if two duplicates
come in now and are staggered between eachother, it shows twice still.
I will try and let you all know...

I would like to say that I didn't expect such great help from the
group. I've thrown a few questions out to different groups but usually
don't have so many great replies. Thank you everyone!|||Have you looked at Kx and Stonebreaker's StreamBase? They are databaes
designed for a high te,mproal flow of data. SQL is not always thje
right tool, in spite of what Bill Gates tells you.|||On Sat, 04 Mar 2006 11:01:08 -0800, BarrySDCA wrote:

> It's exactly what I'm doing....I'm recording hits to an advertising
> engine, before they get to the media server. Some client players hit
> more than once before they connect, causing a duplicate entry. I just
> want to see it sorted out w/out the duplicates. I have the
> distribution server logs for accurate playback reporting, I'm only
> interested in seeing cleaned up hits.

If everything is the same except the timestamp, you can round that up to
the nearest second and use a SELECT DISTINCT.

Check your SQL server's date conversion options to find out how to get
different values from the timestamp field.|||Doug wrote:
> >(but the ID field is still a poor crutch for a possibly weak design.)
> hmmmm. i'd prefer to think of it as the table stores ALL hits to the
> table, but this particular data consumer only wants to see ONE.

It isn't clear that this was ONE of several data consumers.. Even so
the ID pseudokey might not be the best choice.

> The
> way I think about it, your natural key would be the composite of all
> fields in the table; perhaps "natural", but certainly awkword.
> I like figital's solution.

It is not clear from the previous posts that the natural key would
require ALL the columns of that table. If the table is really storing
events, then the key might be as simple as a timestamp, perhaps with an
event type. It doesn't have to be ALL of the columns.

My point is too many people immediately jump to ID fields as the PK.
Many times before they even sit down to think about what entity the
table represents. If you never look for the natural key, you are sure
not to find it.

HTH
ed|||"Ed Prochak" <edprochak@.gmail.com> wrote in message
news:1141752316.933161.102260@.i39g2000cwa.googlegr oups.com...
> My point is too many people immediately jump to ID fields as the PK.

That's certainly a good point. However, I've worked on projects in which
the decision-makers wouldn't commit to _any_ combination of attributes that
would uniquely identify the entity. There were always cases where the value
in any column could be either non-unique, or else have no value specified
(i.e. NULL). Neither would they commit to any attributes that could be
reasonably stable and unchanging (though I understand that this is not
strictly necessary for a key).

So in those kinds of situations, I felt I had to create pseudokeys to have
any chance of the application working. Even if we know the best practices
for database modeling, the project on which we are working may have
constraints that don't allow us to follow those best practices.

Regards,
Bill K.|||Bill Karwin wrote:
> "Ed Prochak" <edprochak@.gmail.com> wrote in message
> news:1141752316.933161.102260@.i39g2000cwa.googlegr oups.com...
> > My point is too many people immediately jump to ID fields as the PK.
> That's certainly a good point. However, I've worked on projects in which
> the decision-makers wouldn't commit to _any_ combination of attributes that
> would uniquely identify the entity. There were always cases where the value
> in any column could be either non-unique, or else have no value specified
> (i.e. NULL). Neither would they commit to any attributes that could be
> reasonably stable and unchanging (though I understand that this is not
> strictly necessary for a key).

It's not necessarily something the End users or even managers should
make the final decision upon. I one really big project I had to good
fortune of working with a real Data Modeler. No she did not
programming, only modelling. She interviewed the users to find out what
data they had, what data they wanted and how they used it. She
organized it and created the ER model. The model included enough
information to design the DB model, which is when the PK's were
determined. Almost all of the cases you mentioned were encountered.
Each was handled by the DB designers. There are times when you create a
pseudokey and times when you split the logical table
maybe to model a more generic entity you create a pair of
parent/child tables where the parent lacks one of the fields that might
be NULL if only the Child table existed, or
maybe the entity really was 2 entities that looked similar, as an
address that represents the customer's location and the adddress that
represents the billing address. A DB that application that needed both
would be poorly served by one ADDRESS table.
What happens internally to the DB does not matter as long as you can
present the right data in the right combinations.

It is our job to engineer the software, not the end users and managers.

> So in those kinds of situations, I felt I had to create pseudokeys to have
> any chance of the application working. Even if we know the best practices
> for database modeling, the project on which we are working may have
> constraints that don't allow us to follow those best practices.
> Regards,
> Bill K.

Sounds like you take pseudokeys as the last resort, which IMO is
exactly what they are. That approach is best practices. Keep it up.

Ed

Monday, March 26, 2012

how can I prevent all jobs start up at the same time?

If I create a job which execute automatically every hour start from 00:00
end to 23:00, does it mean it will start up at the exact 00:00,
01:00.....23:00?
if the answer is true, then if I create many (very very many) jobs which
start automatically in the same rule, will the sql server agent start every
job in the same time? All start up at the exact o'clock?
If the answer is true too, how can I prevent all jobs start up at the same
time?> If I create a job which execute automatically every hour start from 00:00
> end to 23:00, does it mean it will start up at the exact 00:00,
> 01:00.....23:00?
Yes.

> if the answer is true, then if I create many (very very many) jobs which
> start automatically in the same rule, will the sql server agent start ever
y
> job in the same time? All start up at the exact o'clock?
Almost (there may be small differences, usually less than one second).

> If the answer is true too, how can I prevent all jobs start up at the same
> time?
Make only one job with many steps (one step for each job that you would
have created).
Razvan|||if I create every job execute automatically every hour (and everyday) BUT
begin from a random minute (not always from 00:00), can it prevent all jobs
start up at the same time?

> Almost (there may be small differences, usually less than one second).
>|||what is the problem if no. of jobs start at the same time.
If you have any problem you can schedule it some of them at start at
00:00 and repeat after every 1 hour
some start at 00:10 and repeat after every 1 hour so it will run
01:10,02:10 and so on...
Jobs will not run at randomly time from your start time.
Or create one job with multiple steps.
Regards
Amish
*** Sent via Developersdex http://www.examnotes.net ***|||Thanks, I got it.
"Amish Shah" <shahamishm@.gmail.com>
'?:egDI6mRFGHA.532@.TK2MSFTNGP15.phx.gbl...
> what is the problem if no. of jobs start at the same time.
> If you have any problem you can schedule it some of them at start at
> 00:00 and repeat after every 1 hour
> some start at 00:10 and repeat after every 1 hour so it will run
> 01:10,02:10 and so on...
> Jobs will not run at randomly time from your start time.
> Or create one job with multiple steps.
>
>
> Regards
> Amish
> *** Sent via Developersdex http://www.examnotes.net ***|||You could consider a mechanism using sp_start_job from one job to start
another.
I'm wondering why you have so many jobs...But anyhow you could even
use a table to hold the names of jobs and parameterise what starts so
you read the top un-run out a table and mark it as run...|||There is a limited number of threads that Agent will spawn for each job subs
ystem. The value is
specified in the registry (s and you will find). It is probably not suppo
rted to change the
value, unless you find some article (Books Online or KB) that discusses this
.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Frank Lee" <Reply@.to.newsgroup> wrote in message news:ONwlAmQFGHA.2040@.TK2MSFTNGP14.phx.gb
l...
> If I create a job which execute automatically every hour start from 00:00
end to 23:00, does it
> mean it will start up at the exact 00:00, 01:00.....23:00?
> if the answer is true, then if I create many (very very many) jobs which s
tart automatically in
> the same rule, will the sql server agent start every job in the same time?
All start up at the
> exact o'clock?
> If the answer is true too, how can I prevent all jobs start up at the same
time?
>|||I see. Thank you for telling me about that.
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com>
'?:urZFVrTFGHA.2696@.TK2MSFTNGP14.phx.gbl...
> There is a limited number of threads that Agent will spawn for each job
> subsystem. The value is specified in the registry (s and you will
> find). It is probably not supported to change the value, unless you find
> some article (Books Online or KB) that discusses this.
> --

Monday, March 19, 2012

How can I make reports and hide columns at run time with my aspnet app?

Hello. I did a report that has many many columns. I should give the user the
possibility to choose which columns to use with my asp.net program. Is that
possible to do? The only columns that must be shows are the ones that the
user has choosed.

Is that possible. ! !Please help me with links, code, books anythin
neccesary.You can parameterize the report and set the visibilty property on the column to be dependent on the parameter value. If you want to hide mlutiple columns, you will need multiple parmeters or, in SQL 2005, you can have a multivalued parameted. The only downside to this approach is that the body will not shrink with the hidden columns. This can cause problems when printing / exporting the report.

How can I lock and release table

How can I lock and release table
I need to assign user table to acess table only one time and after access
the table will lock
and how to release the table after lock
Thank you for all thinking shareIt's hard to suggest something without more info. Take a look at lock hints
in the BOL
"Pure_haven" <u32445@.uwe> wrote in message news:6f1b82bbe0020@.uwe...
> How can I lock and release table
> I need to assign user table to acess table only one time and after
> access
> the table will lock
> and how to release the table after lock
> Thank you for all thinking share
>

Monday, March 12, 2012

How can I keep my DB secure on SQL Server

hi
this is my 1st time on this forum, I need to keep my DB secure on SQL server, that no body can enter into my DB and couldnt see my tables and other elements of DB.
Regards
AHKALTER DATABASE MyDataBasename SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE|||That's no good, Thrasymachus. Administrators can still get to the data. The only way to make sure that absolutely no one can get to the data, is to kill all the current user connections to the database, drop the database, and run the hard disks the database used to sit on through an MRI machine. Salting the earth is an optional step, but is considered a best practice ;-).

Friday, March 9, 2012

how can i insert time 12:00:00 AM into sql server

my problem is that while i insert Time into datetime coloumn , it shows only 01/01/1900.
it doesn't not shows '01/01/1900 12:00:00 AM'
I run the following query
insert into table1 values('1900/01/01 12:00:00 AM','1900/01/01 11:59:59 PM')
result
column1 Column2
01/01/1900 01/01/1900 11:59:59 PM
how can i solve this problem


If you need to use a SELECT statement to view time, use a CAST or CONVERT. Look these up in SQL help - there are loads of examples

How can I improve my SQL query

Hi,

I have this SQL query that can take too long time, up to 1 minute if table contains over 1 million rows. And if the system is very active while executing this query it can cause more delays I guess.

select
distinct 'CONV 1' as Conveyour,
info as Error,
(select top 1 substring(timecreated, 0, 7) from log b where a.info = b.info order by timecreated asc) as Date,
(select count(*) from log b where b.info = a.info) as 'Times occured'
from log a where loggroup = 'CSCNV' and logtype = 4

The table name is LOG, and I retrieve 4 columns: Conveyour, Error, Date and Times occured. The point of the subqueries is to count all distinct post and to retrieve the date of the first time the pst was logged. Also, a first and last date could be specified but is left out here.

Does anyone knows how I can improve this SQL query?

Best /M

Try to avoid the sub-query, The following query may tune your query performance for some extent,

Code Snippet

select distinct

'conv 1' as conveyour,

info as error,

data.date,

data.[times occured]

from log a

join (select info, substring(min(timecreated),0,7) as date, count(*) as [times occured] from log b)

as data on a.info = data.info

where

loggroup = 'cscnv'

and logtype = 4

|||

Just wrote this quickly, may or may not work.

Code Snippet

SELECT 'CONV 1' AS [Conveyour]
,info AS [Error]
,MAX(substring(timecreated, 0, 7)) AS [Date]
,COUNT(*) AS [Times occured]
FROM log
WHERE loggroup = 'CSCNV'
AND logtype = 4
GROUP
BY info

Chris|||

I am not sure, as per the Moorstream query the where conditions is not controling the timecreated (date) & count.

Its upto Moorstream to choose.. Indifferent

|||

Ah, I see what you mean, forgot about that bit Smile

Would be interesteing to hear the requirement behind that one.

|||

Thank you for your answers, now I have to test these queries and measure execution times

Best,

/M

How can I improve my SQL query

Hi,

I have this SQL query that can take too long time, up to 1 minute if table contains over 1 million rows. And if the system is very active while executing this query it can cause more delays I guess.

select
distinct 'CONV 1' as Conveyour,
info as Error,
(select top 1 substring(timecreated, 0, 7) from log b where a.info = b.info order by timecreated asc) as Date,
(select count(*) from log b where b.info = a.info) as 'Times occured'
from log a where loggroup = 'CSCNV' and logtype = 4

The table name is LOG, and I retrieve 4 columns: Conveyour, Error, Date and Times occured. The point of the subqueries is to count all distinct post and to retrieve the date of the first time the pst was logged. Also, a first and last date could be specified but is left out here.

Does anyone knows how I can improve this SQL query?

Best /M

Try to avoid the sub-query, The following query may tune your query performance for some extent,

Code Snippet

select distinct

'conv 1' as conveyour,

info as error,

data.date,

data.[times occured]

from log a

join (select info, substring(min(timecreated),0,7) as date, count(*) as [times occured] from log b)

as data on a.info = data.info

where

loggroup = 'cscnv'

and logtype = 4

|||

Just wrote this quickly, may or may not work.

Code Snippet

SELECT 'CONV 1' AS [Conveyour]
,info AS [Error]
,MAX(substring(timecreated, 0, 7)) AS [Date]
,COUNT(*) AS [Times occured]
FROM log
WHERE loggroup = 'CSCNV'
AND logtype = 4
GROUP
BY info

Chris|||

I am not sure, as per the Moorstream query the where conditions is not controling the timecreated (date) & count.

Its upto Moorstream to choose.. Indifferent

|||

Ah, I see what you mean, forgot about that bit Smile

Would be interesteing to hear the requirement behind that one.

|||

Thank you for your answers, now I have to test these queries and measure execution times

Best,

/M

Monday, February 27, 2012

How can i get time?

There is a field which type is datetime in my table, when the filed is '2006-06-03 23:00:00', how can i get '2006-06-03' from the field?

TRY THIS

SELECT CONVERT(VARCHAR(10), '2006-06-03 23:00:00')

REGARDS

ANAS

|||

This only works if the field is a varchar. You would need to set a different style or you will get "Jun 3 200". See below...

IF OBJECT_ID('test', 'U') IS NOT NULL

DROP TABLE dbo.test

GO

CREATE TABLE dbo.test

(

testDate datetime

)

INSERT dbo.test (testDate) VALUES ('2006-06-03 23:00:00')

--This returns "Jun 3 200"

SELECT CONVERT(VARCHAR(10), testDate) FROM dbo.test

--This returns 2006-06-03

SELECT REPLACE(CONVERT(VARCHAR(10), testDate, 102), '.', '-') FROM dbo.test

How can I get the log sequence number on C#?

Hi! I would like to get the log sequence number from the database backup so
that I can let the users select the restored time. Can I do this with the
SMO?
Thanks!One way would be to use methods such as the Database.ExecuteWithResults method to execute your
RESTORE HEADERONLY command and loop the result (DataTable in the DataSet) from that method.
Or, you should be able to use BackupDevice.ReadBackupHeader method and read the returned DataTable.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Cheryl" <justtosayhi@.excite.com> wrote in message
news:FBB10E85-25FF-49B7-96D4-97ADE7552575@.microsoft.com...
> Hi! I would like to get the log sequence number from the database backup so that I can let the
> users select the restored time. Can I do this with the SMO?
> Thanks!

Sunday, February 19, 2012

How can I find records of a table which inserted today(for example)

Hi
My question is How can i find records of a table which insterted today(for
example) or after a specified time.
Thanks a lotA double post...
Please see response to previous question...
HTH. Ryan
"Hayatbakhsh" <hayatbakhsh@.gmail.com> wrote in message
news:upFAe6aIGHA.3056@.TK2MSFTNGP09.phx.gbl...
> Hi
> My question is How can i find records of a table which insterted today(for
> example) or after a specified time.
> Thanks a lot
>