Showing posts with label apologies. Show all posts
Showing posts with label apologies. Show all posts

Thursday, March 29, 2012

Correct way to create indices? SQLServer Express 2005

Hi,

Apologies if this has been asked before, i've done a search but can't find a definitive answer.

I've created a table in an SQLExpress 2005 db using Server Managment Studio Express.

My intention is to use GUID fields as surrogate PK's. I therefore wanted to add a additional index to prevent duplicate records being added to the table. Not having used SQLServer before could someone confirm or deny that this is the correct way to do this. The PK field [EPISODEID{unique identifier}] is set as a non-clustered index. And i've created a second clustered index using the two fields that create a unique record. I've added a screen shot if that is any help.

Thanks

Chris

You can do that, yes. But I would normally leave the PK as the clustered index, since that should be how the majority of your records are located. If it isn't then you need to sit down and think what purpose your surrogate key is supposed to provide.

|||

Motley wrote:

You can do that, yes. But I would normally leave the PK as the clustered index, since that should be how the majority of your records are located. If it isn't then you need to sit down and think what purpose your surrogate key is supposed to provide.

Thanks very much for your replySmile [:)]

I've read up quite a lot of posts and articles regarding the use of surrogate vs natural keys. My primary reason for choosing surrogate keys is the inability to guarantee access to values which would create a natural key that didn't need changing. For example a head injured patient arrives at hospital and is assessed by the team i am working for. This is common as i work for critical care services which include Neurologically impared patients. They need a unique id for that patient but have no access to a possible natural key, the patients NHS number. In this case it's easier to generate a surrogate PK like a GUID which can be used on all the joins required in the database and use an incremental value from a store to replace the NHS number and keep the record unique until the NHS number can be assertained. Even then if the patient is non-uk resident they will never have an NHS number. However if the NHS number is found at a later date the PK can remain intact it's just a case of updating the NHS number field rather than cascading a changing PK through the database.

Anyways,

If i've got this correct the purpose of clustering an index is to create some form of sorting on sequentially related values which helps with retrieving records i.e. dates

If that's correct then as a surrogate key doesn't [or shouldn't] contain data relating to the contents of the record it indentifies it wouldn't matter if it is clustered or not. I think that this would particularly be the case with GUIDs as there is no logical sequence to their creation that would be worth clustering as compared to a sequential integer that might provide a pseudo order of entry index.

The second index i've created i've set as a clustered index as that is the one that holds the data which is used for retrieval i.e. finding all patient episodes within a given date range, so sorting would be beneficial and the unique index constraint should prevent duplication of records.

I've tried to follow the advice given on msdn regarding creating indicies i just wasn't sure if i'd actually done it correctly in Express05. Of course i may have missed the point entirelyEmbarrassed [:$]

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/createdb/cm_8_des_05_8185.asp

Thanks again

Chris.

Wednesday, March 7, 2012

Copying a subset from SQL Server

Newbie question: (apologies all)
How does one download a subset from server to notebook?
Practical problem: Executive visiting customer wants database on customer.
Sharepoint and Project 2003 data.
Thank you
Brent Rowell
"Brent Rowell" <anonymous@.discussions.microsoft.com> wrote in message
news:D4B70D84-AA6E-4B1E-929C-C9F7C770B84B@.microsoft.com...
> Newbie question: (apologies all)
> How does one download a subset from server to notebook?
> Practical problem: Executive visiting customer wants database on customer.
> Sharepoint and Project 2003 data.
Once you've got MSDE installed on the laptop, you could use Enterprise
Manager and DTS to transfer the data subset you need from the server to the
notebook...
Steve
|||Thank you
Brent
"Steve Thompson" <SteveThompson@.nomail.please> wrote in message
news:O0WrUcMIEHA.828@.TK2MSFTNGP12.phx.gbl...
> "Brent Rowell" <anonymous@.discussions.microsoft.com> wrote in message
> news:D4B70D84-AA6E-4B1E-929C-C9F7C770B84B@.microsoft.com...
customer.
> Once you've got MSDE installed on the laptop, you could use Enterprise
> Manager and DTS to transfer the data subset you need from the server to
the
> notebook...
> Steve
>
|||"Brent Rowell" <brent@.pls_remove_jrowell.com> wrote in message news:<eEYV2wPIEHA.3200@.TK2MSFTNGP10.phx.gbl>...[vbcol=seagreen]
> Thank you
> Brent
> "Steve Thompson" <SteveThompson@.nomail.please> wrote in message
> news:O0WrUcMIEHA.828@.TK2MSFTNGP12.phx.gbl...
> customer.
> the
You could use Super*SQL to create an ASCII file containing all of the
database tables, then copy the file to the notebook and load into the
local database. I found the Beta version at www.sqlmagic.com.

Monday, February 13, 2012

Copy SQL Server Row - Repost

Hello all,
I've reposted this message as I didn't make it to clear what i'm
trying to achive in an earlier post - my apologies.
I need to write a procedure that will SELECT a row in a table and
INSERT the values into the same table, however, one of the columns,
'ID' is a PK with Identity set to 'Yes'. Obviously this won't work as
it will try to INSERT a row with a key that has the same value. So, is
there a way to do this without having to specify every field in the
SELECT clause and auto incrementing the 'ID' value?
Thanks all,
JY
Jon
You WILL have to specify all columns except ID
"Jon" <JonMYates@.gmail.com> wrote in message
news:1178711070.737514.324520@.e51g2000hsg.googlegr oups.com...
> Hello all,
> I've reposted this message as I didn't make it to clear what i'm
> trying to achive in an earlier post - my apologies.
> I need to write a procedure that will SELECT a row in a table and
> INSERT the values into the same table, however, one of the columns,
> 'ID' is a PK with Identity set to 'Yes'. Obviously this won't work as
> it will try to INSERT a row with a key that has the same value. So, is
> there a way to do this without having to specify every field in the
> SELECT clause and auto incrementing the 'ID' value?
> Thanks all,
> JY
>
|||> So, is
> there a way to do this without having to specify every field in the
> SELECT clause and auto incrementing the 'ID' value?
No, you'll need to specify a column list. It's a Best Practice to specify
an explicit column list, even without the IDENTITY issue. Query
Analyzer/Management Studio allow you to script SELECTs so you don't need to
type the list manually.
Hope this helps.
Dan Guzman
SQL Server MVP
"Jon" <JonMYates@.gmail.com> wrote in message
news:1178711070.737514.324520@.e51g2000hsg.googlegr oups.com...
> Hello all,
> I've reposted this message as I didn't make it to clear what i'm
> trying to achive in an earlier post - my apologies.
> I need to write a procedure that will SELECT a row in a table and
> INSERT the values into the same table, however, one of the columns,
> 'ID' is a PK with Identity set to 'Yes'. Obviously this won't work as
> it will try to INSERT a row with a key that has the same value. So, is
> there a way to do this without having to specify every field in the
> SELECT clause and auto incrementing the 'ID' value?
> Thanks all,
> JY
>

Copy SQL Server Row - Repost

Hello all,
I've reposted this message as I didn't make it to clear what i'm
trying to achive in an earlier post - my apologies.
I need to write a procedure that will SELECT a row in a table and
INSERT the values into the same table, however, one of the columns,
'ID' is a PK with Identity set to 'Yes'. Obviously this won't work as
it will try to INSERT a row with a key that has the same value. So, is
there a way to do this without having to specify every field in the
SELECT clause and auto incrementing the 'ID' value?
Thanks all,
JYJon
You WILL have to specify all columns except ID
"Jon" <JonMYates@.gmail.com> wrote in message
news:1178711070.737514.324520@.e51g2000hsg.googlegroups.com...
> Hello all,
> I've reposted this message as I didn't make it to clear what i'm
> trying to achive in an earlier post - my apologies.
> I need to write a procedure that will SELECT a row in a table and
> INSERT the values into the same table, however, one of the columns,
> 'ID' is a PK with Identity set to 'Yes'. Obviously this won't work as
> it will try to INSERT a row with a key that has the same value. So, is
> there a way to do this without having to specify every field in the
> SELECT clause and auto incrementing the 'ID' value?
> Thanks all,
> JY
>|||> So, is
> there a way to do this without having to specify every field in the
> SELECT clause and auto incrementing the 'ID' value?
No, you'll need to specify a column list. It's a Best Practice to specify
an explicit column list, even without the IDENTITY issue. Query
Analyzer/Management Studio allow you to script SELECTs so you don't need to
type the list manually.
Hope this helps.
Dan Guzman
SQL Server MVP
"Jon" <JonMYates@.gmail.com> wrote in message
news:1178711070.737514.324520@.e51g2000hsg.googlegroups.com...
> Hello all,
> I've reposted this message as I didn't make it to clear what i'm
> trying to achive in an earlier post - my apologies.
> I need to write a procedure that will SELECT a row in a table and
> INSERT the values into the same table, however, one of the columns,
> 'ID' is a PK with Identity set to 'Yes'. Obviously this won't work as
> it will try to INSERT a row with a key that has the same value. So, is
> there a way to do this without having to specify every field in the
> SELECT clause and auto incrementing the 'ID' value?
> Thanks all,
> JY
>

Copy SQL Server Row - Repost

Hello all,
I've reposted this message as I didn't make it to clear what i'm
trying to achive in an earlier post - my apologies.
I need to write a procedure that will SELECT a row in a table and
INSERT the values into the same table, however, one of the columns,
'ID' is a PK with Identity set to 'Yes'. Obviously this won't work as
it will try to INSERT a row with a key that has the same value. So, is
there a way to do this without having to specify every field in the
SELECT clause and auto incrementing the 'ID' value?
Thanks all,
JYJon
You WILL have to specify all columns except ID
"Jon" <JonMYates@.gmail.com> wrote in message
news:1178711070.737514.324520@.e51g2000hsg.googlegroups.com...
> Hello all,
> I've reposted this message as I didn't make it to clear what i'm
> trying to achive in an earlier post - my apologies.
> I need to write a procedure that will SELECT a row in a table and
> INSERT the values into the same table, however, one of the columns,
> 'ID' is a PK with Identity set to 'Yes'. Obviously this won't work as
> it will try to INSERT a row with a key that has the same value. So, is
> there a way to do this without having to specify every field in the
> SELECT clause and auto incrementing the 'ID' value?
> Thanks all,
> JY
>|||> So, is
> there a way to do this without having to specify every field in the
> SELECT clause and auto incrementing the 'ID' value?
No, you'll need to specify a column list. It's a Best Practice to specify
an explicit column list, even without the IDENTITY issue. Query
Analyzer/Management Studio allow you to script SELECTs so you don't need to
type the list manually.
Hope this helps.
Dan Guzman
SQL Server MVP
"Jon" <JonMYates@.gmail.com> wrote in message
news:1178711070.737514.324520@.e51g2000hsg.googlegroups.com...
> Hello all,
> I've reposted this message as I didn't make it to clear what i'm
> trying to achive in an earlier post - my apologies.
> I need to write a procedure that will SELECT a row in a table and
> INSERT the values into the same table, however, one of the columns,
> 'ID' is a PK with Identity set to 'Yes'. Obviously this won't work as
> it will try to INSERT a row with a key that has the same value. So, is
> there a way to do this without having to specify every field in the
> SELECT clause and auto incrementing the 'ID' value?
> Thanks all,
> JY
>