Showing posts with label regarding. Show all posts
Showing posts with label regarding. Show all posts

Wednesday, March 21, 2012

Detect changes on indexes in a published table

Hi,

Regarding to my previous post at http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=553652&SiteID=1, just wondering if there's a way to detect any changes which is made on the existing indexes in a published table so that the device can determine whether reinitialization of subscrption is needed before every synchronization.

Cheers,
Justin

One thing you may be able to use is DDL trigger. DDL trigger are fired in response to a variety of DDL statements, including create/alter/drop index. Just look for DDL trigger in BOL for more information.

Peng

|||

Yes, you may use special tools for compare structure changes

link http://www.red-gate.com/products/index.htm

sql

Monday, March 19, 2012

Detaching MDF/LDF files to SQL Server 2005 running on MSCS

I am planning to do the following when migrating to SQL Server 2005 running
on MSCS. Are there any issues or gotchas I should know regarding these steps:
1) Restore SQL 2000 database to SQL Server 2005 machine ( stand alone server
using SAN as the storage for DB files )
2) Run DB backup ( SQL 2005 ) on stand alone server
3) Run migration scripts ( the build scripts changes 80% of the db schema )
4) Run DB backup ( SQL 2005 )
5) Detach the DB
6) Attach the DB on SQL Server 2005 running on MS Cluster environment ( same
DB files on SAN storage)
The problem is that we have limited servers and the database servers
currently used as production will become unavailable when we move these
machines to become nodes within the cluster environment.
--
Lito DIf you use SQL Server Logins (SQL Server authentication) you might want to
make sure that you create the account on the new server with the same SID as
on the current server.
--
Keith Kratochvil
"LITO" <anynomous@.msn.com> wrote in message
news:8A203EF5-EC88-4455-A841-1021A63D1DEC@.microsoft.com...
>I am planning to do the following when migrating to SQL Server 2005 running
> on MSCS. Are there any issues or gotchas I should know regarding these
> steps:
> 1) Restore SQL 2000 database to SQL Server 2005 machine ( stand alone
> server
> using SAN as the storage for DB files )
> 2) Run DB backup ( SQL 2005 ) on stand alone server
> 3) Run migration scripts ( the build scripts changes 80% of the db
> schema )
> 4) Run DB backup ( SQL 2005 )
> 5) Detach the DB
> 6) Attach the DB on SQL Server 2005 running on MS Cluster environment (
> same
> DB files on SAN storage)
> The problem is that we have limited servers and the database servers
> currently used as production will become unavailable when we move these
> machines to become nodes within the cluster environment.
> --
> Lito D|||Thank you, Keith. Question, do you mean create the account on SQL Server
2005 then run sp_change_users_login? Can you give me specifics on how to do
this?
Thanks again.
--
Lito D
"Keith Kratochvil" wrote:
> If you use SQL Server Logins (SQL Server authentication) you might want to
> make sure that you create the account on the new server with the same SID as
> on the current server.
> --
> Keith Kratochvil
>
> "LITO" <anynomous@.msn.com> wrote in message
> news:8A203EF5-EC88-4455-A841-1021A63D1DEC@.microsoft.com...
> >I am planning to do the following when migrating to SQL Server 2005 running
> > on MSCS. Are there any issues or gotchas I should know regarding these
> > steps:
> >
> > 1) Restore SQL 2000 database to SQL Server 2005 machine ( stand alone
> > server
> > using SAN as the storage for DB files )
> > 2) Run DB backup ( SQL 2005 ) on stand alone server
> > 3) Run migration scripts ( the build scripts changes 80% of the db
> > schema )
> > 4) Run DB backup ( SQL 2005 )
> > 5) Detach the DB
> > 6) Attach the DB on SQL Server 2005 running on MS Cluster environment (
> > same
> > DB files on SAN storage)
> >
> > The problem is that we have limited servers and the database servers
> > currently used as production will become unavailable when we move these
> > machines to become nodes within the cluster environment.
> > --
> > Lito D
>
>|||You only need to run sp_change_users_login if the SID for the login on the
server is different than the user's SID within the database.
To prevent this problem from happening on your new server you can specify
the SID during the CREATE LOGIN process on the SQL 2005 box (SID = is one of
the params that you can use during the CREATE LOGIN process)
This query should give you a list of sql logins and their SID on the SQL
2000 box:
select name, sid
from master..syslogins
where isntgroup = 0
--
Keith Kratochvil
"LITO" <anynomous@.msn.com> wrote in message
news:DDC1D8DD-9400-4E6F-AB3F-936111654344@.microsoft.com...
> Thank you, Keith. Question, do you mean create the account on SQL Server
> 2005 then run sp_change_users_login? Can you give me specifics on how to
> do
> this?
> Thanks again.
> --
> Lito D
>
> "Keith Kratochvil" wrote:
>> If you use SQL Server Logins (SQL Server authentication) you might want
>> to
>> make sure that you create the account on the new server with the same SID
>> as
>> on the current server.
>> --
>> Keith Kratochvil
>>
>> "LITO" <anynomous@.msn.com> wrote in message
>> news:8A203EF5-EC88-4455-A841-1021A63D1DEC@.microsoft.com...
>> >I am planning to do the following when migrating to SQL Server 2005
>> >running
>> > on MSCS. Are there any issues or gotchas I should know regarding these
>> > steps:
>> >
>> > 1) Restore SQL 2000 database to SQL Server 2005 machine ( stand alone
>> > server
>> > using SAN as the storage for DB files )
>> > 2) Run DB backup ( SQL 2005 ) on stand alone server
>> > 3) Run migration scripts ( the build scripts changes 80% of the db
>> > schema )
>> > 4) Run DB backup ( SQL 2005 )
>> > 5) Detach the DB
>> > 6) Attach the DB on SQL Server 2005 running on MS Cluster environment (
>> > same
>> > DB files on SAN storage)
>> >
>> > The problem is that we have limited servers and the database servers
>> > currently used as production will become unavailable when we move these
>> > machines to become nodes within the cluster environment.
>> > --
>> > Lito D
>>

Sunday, March 11, 2012

Detaching MDF/LDF files to SQL Server 2005 running on MSCS

I am planning to do the following when migrating to SQL Server 2005 running
on MSCS. Are there any issues or gotchas I should know regarding these steps:
1) Restore SQL 2000 database to SQL Server 2005 machine ( stand alone server
using SAN as the storage for DB files )
2) Run DB backup ( SQL 2005 ) on stand alone server
3) Run migration scripts ( the build scripts changes 80% of the db schema )
4) Run DB backup ( SQL 2005 )
5) Detach the DB
6) Attach the DB on SQL Server 2005 running on MS Cluster environment ( same
DB files on SAN storage)
The problem is that we have limited servers and the database servers
currently used as production will become unavailable when we move these
machines to become nodes within the cluster environment.
Lito D
If you use SQL Server Logins (SQL Server authentication) you might want to
make sure that you create the account on the new server with the same SID as
on the current server.
Keith Kratochvil
"LITO" <anynomous@.msn.com> wrote in message
news:8A203EF5-EC88-4455-A841-1021A63D1DEC@.microsoft.com...
>I am planning to do the following when migrating to SQL Server 2005 running
> on MSCS. Are there any issues or gotchas I should know regarding these
> steps:
> 1) Restore SQL 2000 database to SQL Server 2005 machine ( stand alone
> server
> using SAN as the storage for DB files )
> 2) Run DB backup ( SQL 2005 ) on stand alone server
> 3) Run migration scripts ( the build scripts changes 80% of the db
> schema )
> 4) Run DB backup ( SQL 2005 )
> 5) Detach the DB
> 6) Attach the DB on SQL Server 2005 running on MS Cluster environment (
> same
> DB files on SAN storage)
> The problem is that we have limited servers and the database servers
> currently used as production will become unavailable when we move these
> machines to become nodes within the cluster environment.
> --
> Lito D
|||Thank you, Keith. Question, do you mean create the account on SQL Server
2005 then run sp_change_users_login? Can you give me specifics on how to do
this?
Thanks again.
Lito D
"Keith Kratochvil" wrote:

> If you use SQL Server Logins (SQL Server authentication) you might want to
> make sure that you create the account on the new server with the same SID as
> on the current server.
> --
> Keith Kratochvil
>
> "LITO" <anynomous@.msn.com> wrote in message
> news:8A203EF5-EC88-4455-A841-1021A63D1DEC@.microsoft.com...
>
>
|||You only need to run sp_change_users_login if the SID for the login on the
server is different than the user's SID within the database.
To prevent this problem from happening on your new server you can specify
the SID during the CREATE LOGIN process on the SQL 2005 box (SID = is one of
the params that you can use during the CREATE LOGIN process)
This query should give you a list of sql logins and their SID on the SQL
2000 box:
select name, sid
from master..syslogins
where isntgroup = 0
Keith Kratochvil
"LITO" <anynomous@.msn.com> wrote in message
news:DDC1D8DD-9400-4E6F-AB3F-936111654344@.microsoft.com...[vbcol=seagreen]
> Thank you, Keith. Question, do you mean create the account on SQL Server
> 2005 then run sp_change_users_login? Can you give me specifics on how to
> do
> this?
> Thanks again.
> --
> Lito D
>
> "Keith Kratochvil" wrote:

Detaching MDF/LDF files to SQL Server 2005 running on MSCS

I am planning to do the following when migrating to SQL Server 2005 running
on MSCS. Are there any issues or gotchas I should know regarding these step
s:
1) Restore SQL 2000 database to SQL Server 2005 machine ( stand alone server
using SAN as the storage for DB files )
2) Run DB backup ( SQL 2005 ) on stand alone server
3) Run migration scripts ( the build scripts changes 80% of the db schema )
4) Run DB backup ( SQL 2005 )
5) Detach the DB
6) Attach the DB on SQL Server 2005 running on MS Cluster environment ( same
DB files on SAN storage)
The problem is that we have limited servers and the database servers
currently used as production will become unavailable when we move these
machines to become nodes within the cluster environment.
--
Lito DIf you use SQL Server Logins (SQL Server authentication) you might want to
make sure that you create the account on the new server with the same SID as
on the current server.
Keith Kratochvil
"LITO" <anynomous@.msn.com> wrote in message
news:8A203EF5-EC88-4455-A841-1021A63D1DEC@.microsoft.com...
>I am planning to do the following when migrating to SQL Server 2005 running
> on MSCS. Are there any issues or gotchas I should know regarding these
> steps:
> 1) Restore SQL 2000 database to SQL Server 2005 machine ( stand alone
> server
> using SAN as the storage for DB files )
> 2) Run DB backup ( SQL 2005 ) on stand alone server
> 3) Run migration scripts ( the build scripts changes 80% of the db
> schema )
> 4) Run DB backup ( SQL 2005 )
> 5) Detach the DB
> 6) Attach the DB on SQL Server 2005 running on MS Cluster environment (
> same
> DB files on SAN storage)
> The problem is that we have limited servers and the database servers
> currently used as production will become unavailable when we move these
> machines to become nodes within the cluster environment.
> --
> Lito D|||Thank you, Keith. Question, do you mean create the account on SQL Server
2005 then run sp_change_users_login? Can you give me specifics on how to do
this?
Thanks again.
--
Lito D
"Keith Kratochvil" wrote:

> If you use SQL Server Logins (SQL Server authentication) you might want to
> make sure that you create the account on the new server with the same SID
as
> on the current server.
> --
> Keith Kratochvil
>
> "LITO" <anynomous@.msn.com> wrote in message
> news:8A203EF5-EC88-4455-A841-1021A63D1DEC@.microsoft.com...
>
>|||You only need to run sp_change_users_login if the SID for the login on the
server is different than the user's SID within the database.
To prevent this problem from happening on your new server you can specify
the SID during the CREATE LOGIN process on the SQL 2005 box (SID = is one of
the params that you can use during the CREATE LOGIN process)
This query should give you a list of sql logins and their SID on the SQL
2000 box:
select name, sid
from master..syslogins
where isntgroup = 0
Keith Kratochvil
"LITO" <anynomous@.msn.com> wrote in message
news:DDC1D8DD-9400-4E6F-AB3F-936111654344@.microsoft.com...[vbcol=seagreen]
> Thank you, Keith. Question, do you mean create the account on SQL Server
> 2005 then run sp_change_users_login? Can you give me specifics on how to
> do
> this?
> Thanks again.
> --
> Lito D
>
> "Keith Kratochvil" wrote:
>

Saturday, February 25, 2012

designing for encryption ...

In light of SARBOX, ChoicePoint security breaches, identity theft etc, what
are some best practices regarding encryption and security of this type of
info? I know this is a pretty broad question, so links to other sites are
great, but I'd like to hear some personal experiences and opinions.
The reason is I have identified what I consider potential security problems
in our systems. I need to get get a sense of how critical these particular
issues are (I tend to take the position that hyper vigilence is best so for
me everything is critical) and get them in front of management to hopefully
get some action. But I always think it's best to have at least a proposal
for a solution when presenting a problem.
Anyway, any feedback is most appreciated.
Bob Castleman
DBA PoseurHere is a little something from a mind far greater than mine...
http://vyaskn.tripod.com/sql_server...t_practices.htm
Peter
"The length of this document defends it well against the risk of its being
read."
Winston Churchill
"Bob Castleman" wrote:

> In light of SARBOX, ChoicePoint security breaches, identity theft etc, wha
t
> are some best practices regarding encryption and security of this type of
> info? I know this is a pretty broad question, so links to other sites are
> great, but I'd like to hear some personal experiences and opinions.
> The reason is I have identified what I consider potential security problem
s
> in our systems. I need to get get a sense of how critical these particular
> issues are (I tend to take the position that hyper vigilence is best so fo
r
> me everything is critical) and get them in front of management to hopefull
y
> get some action. But I always think it's best to have at least a proposal
> for a solution when presenting a problem.
> Anyway, any feedback is most appreciated.
> Bob Castleman
> DBA Poseur
>
>|||SARBOX is not an area I'm expert in but one thing I know about security
is that it isn't the same as encryption. Encryption is just one tool
for security. So "designing for security" is something different from
"designing for encryption" and I would advise you to focus on the
former rather than the latter. As I understand it SARBOX does NOT
mandate that any data be encrypted it just requires "adequate" internal
controls.
David Portas
SQL Server MVP
--|||I believe that Sarbanes Oxley suggests or recommends all "Sensitive" data be
encrypted in a data store.
SSNs
Account Numbers
Visa Numbers
etc etc etc
I could be wrong (I'm not a SOX Audit expert either)
Greg Jackson
PDX, Oregon|||Not a lawyer or security expert but California law, SB 1386
(http://info.sen.ca.gov/pub/01-02/bi...86_bill_2002092
6_chaptered.html) mentions unencrypted data. It seems that if someone where
to breach your database and personal information was encrypted you would not
need to disclose the breach.
See [url]http://informationw.com/story/showArticle.jhtml?articleID=10700814[/url]
for an overview...
"pdxJaxon" <GregoryAJackson@.Hotmail.com> wrote in message
news:%23Jf3G$8LFHA.576@.TK2MSFTNGP15.phx.gbl...
> I believe that Sarbanes Oxley suggests or recommends all "Sensitive" data
be
> encrypted in a data store.
> SSNs
> Account Numbers
> Visa Numbers
> etc etc etc
> I could be wrong (I'm not a SOX Audit expert either)
> Greg Jackson
> PDX, Oregon
>

Friday, February 24, 2012

Design question regarding comma delimited data

Hi,

I'm trying to figure out if it's good design practice to have several pieces of data in a one column. I explain by example. Let's say you build a movie site. Each movie can belong to several categories. A movie can be Action, Adventure, Fantasy and Drama all at once. Assume a database table with all the movies and another table with all the categories. Now how would I associate one movie with several categories? Would it be OK if I add a Category field in the movie table and then add several categories in that, delimited by commas? Sort of like below:

movie_title | movie_rating | category_name
------------------------------
Pirates of the Carribean | PG-13 | Action,Adventure,Fantasy
Evil Dead | Unrated | Horror

and so on ...

I can then query the database with a LIKE query if I want to select all movies of a certain category. Personally, I don't like this approach to much, but I can't think of another way to achieve this. Well, there is one other, but I like that one even less. I could create another table that links each movie to a category, but his way each movie with several categories would get a new row. Using the table above, Pirates would get three rows in that table. One with Action, one with Adventure and one with Fantasy. Get my drift?


It all seems counter-intuitive. Thoughts?

Thanks :o)

You should go with the second approach (separate table where you store MovieId, CategoryId) unless you have a good reason to not do it so.

Think about the fact that search by category is not the only possible query you will need. How would you do implement the following using your first approach:Select the number of movies in each category? Using a separate table you can just group by category and do a count().

Keep in mind that normalization is almost always a good thing to do. If you don't know what that means you really have to take a book on database design and read about it.

|||

Create a child table that joins the two tables together

Your Movies Table
MovieID int identity PK
Title varchar
Rating varchar

Your Categories Table
CategoryID int identity PK
Name varchar

Your MovieCategories table
MovieID int
CategoryID int

So if you enter a movie in the Movies table
Title: Pirates of the Carribean
Rating: PG-13

It would get assigned an auto-incrementing ID (in this case 1)

You then populate your Category Table with things like
Action (gets assigned 1)
Adventure (gets assigned 2)
Drama (gets assigned 3)
Comedy (gets assigned 4)
Fantasy (gets assigned 5)

Then in your child table you assign the MovieID for Pirates with the CategoryID's that it belongs to
MovieID CategoryID
1 1
1 2
1 5

Then when you query you would join the necessary tables together to get what you are after.

|||

>>Now how would I associate one movie with several categories?

The method you described isvery typical ( a third table to link the other two).

Table: MovieCategoriesMovieID CatID1 11 32 23 13 23 3
This is the utilimate in flexibility but requires more work from you.
A quick and dirty way (not always bad) would be a boolean column for each category.
This assumes that categories are fixed and you will not be adding new categories

|||

The best will be to create table

Movie with MovieID and Movietittle

Ratings with RatingID and RatingName

Category CategoryID and categoryname

and two tables to link your information

MovieRatings with mrID, mrMovieID, mrRatingID

MOvieCategory with mcID, mcMovieID ,mcCategoryID

With this structure your queries will be much faster when with like statement and also it will save you same space in database

You can have multiple categories connected to movie in movie category table and also different ratings if you need.

Thanks

|||

Thanks for all the replies.

See, I used the, for lack of a better word, "third table" approach before. It's the only way I could think of doing what I wanted it to do. I just never liked that idea of having to create another table. But apparently this is pretty common, so I don't feel so bad about it anymore :o)

It's basically going to look like this:

Movies

movie_id movie_title movie_rating
-------------
1 Bad Movie PG
2 Cool Movie R
3 So So Movie PG-13

Categories

category_id category_name
----------
1 Action
2 Adventure
3 Comedy
4 Drama

Movies/Categories

movie_id category_id
--------
1 1
1 2
2 3
2 4
3 3

I guess that makes good sense, but it always seemed redundant.

Thanks :o)

Tuesday, February 14, 2012

Design Advice

Hello - this is my first post (just found the site today). I'm looking for advice regarding the following design issue(s):

I have a VB batch job that runs a couple of times throughout the day - each time it runs, it inserts approximately 100k rows to a table (call it Table A). I need to be able to view the inserted data by batch run and in aggregate. Obviously querying the table has now become too expensive to produce aggregate reports.

I'd like to create an aggregate table (call it Table B) so that as rows are inserted into Table A, Table B is updated to reflect running totals.

Currently, the batch job inserts records into Table A by using the ADO batchupdate method. If I were to stick with this, then I could create a trigger to update Table B as records are inserted into Table A.

Question 1: Is it posssible to create a trigger that will update if the record exists or insert if it doesn't? What kind of overhead does that represent?

Question 2: If instead of using the updatebatch method, I call a stored procedure to insert each of the records into Table A and also insert/update Table B, will I suffer a performance hit?

Sorry for the long post, just wanted to make sure I didn't leave anything out. TIA for any help you can offer!In answer to your questions

1) You can create a trigger on Table A that updates/inserts into TableB.
UPDATE
SET value = value+i.Increment
FROM inserted i,
TableB b
WHERE b.Key = i.Key

INSERT TableB (col1,col2,col3,...)
SELECT col1,col2,col3,...
FROM inserted i
WHERE NOT EXISTS
(
SELECT *
FROM TableB b
WHERE b.Key = i.Key
)
This is just an idea on how you can do it. You could simplify the INSERT part if only one record is in the INSERTED table. You may need to think about what should happen to the values in TableB if TableA is updated?

2) Stored procedure are allows the way to go and increase performance, however when it comes to bulk operations or single operation with stored procedure, I like bulk. If you could combine the 2 that would be great.