Showing posts with label unique. Show all posts
Showing posts with label unique. Show all posts

Friday, March 30, 2012

Need to create case sensitive Uniqiue Indexes

Hi,

How Can I create a case sensitive unique index so that A1 and a1 are treated
as different ?

I dont mind if I have to make a global DB change.

SteveSteve Thorpe (stephenthorpe@.nospam.hotmail.com) writes:
> How Can I create a case sensitive unique index so that A1 and a1 are
> treated as different ?
> I dont mind if I have to make a global DB change.

You should change the database to use a case-sensitive collation - and
maybe the entire server, since collation mix on the same server can
cause problems with tempdb.

You can achieve this in several ways. You can bulk out all data and
build a new database from scripts where you have changed the collation
and then bulk data back. You can also issue ALTER TABLE ALTER COLUMN
for all columns with character data. You also need to use ALTER COLLATION
SET COLLATION. (This latter command sets the default for future columns,
but does not affect existing ones.)

To change the collation for master, you use the rebuildm facility.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Monday, March 12, 2012

Need random/unique "IDs" for key verification

I need to be able to create completely random and unique keys for a key verification system, which would require a user to enter a pre-defined key in order to activate their account, but I need to be able to create those keys on the fly.

This is going to be a key that will be mailed to them on paper, and unfortunately means it needs to be relatively short in order to prevent too much confusion while they are typing it in.

I like the newID() function in SQL, but the ID that it creates is a bit excessive to say the least for someone to have to type when registerring.

I use C#, so I wouldn't have much of a problem creating a small app to create x number of keys, which will sit in the DB until I need them, but I would rather not have to fill the DB with a million or so ID's which might never be used, and don't want to create too little that I have to track when I might need to add more, in case I start to run low on ID's.

Re-using ID's may be an option, but I would prefer to keep them intact for the life of the accounts.

If there is something that I can do to simulate the newID() function, but generate unique/random ID's which look more like this: A97-2C5-77D than this: A972C577-DFB0-064E-1189-0154C99310DAAC12 I would be very grateful to know about it.

Thanks!

You could use Membership.GeneratePassword Method

It allows control of length and complexity both of the generated password

http://msdn2.microsoft.com/en-us/library/system.web.security.membership.generatepassword.aspx

Monday, February 20, 2012

need help with unique SQL data view

The objective here is to create a SQL data view of two tables that have a on
e
to many relationship. The two tables represent a simple category/subcategor
y
relationship and the common value that will need to be returned will be the
name and its primary key (unique identifier). Let me represent the desired
result by the following example.
This represents the table/field schema:
TABLE 1 – CATEGORY
category_id
name
TABLE 2 – SUBCATEGORY
category_id
name
parent_id (relates to category_id in TABLE 1- CATEGORY)
The following represents the top level CATEGORY sample data:
TABLE 1 – CATEGORY
Name
Foundation
Slab
Rough Shell
Mechanicals
Finish Trades
Appliances
The second representation is the related SUBCATEGORY sample data:
TABLE 1 – SUBCATEGORY
Parent_Name Name
Rough Shell Framing
Rough Shell Windows
Rough Shell Doors
Appliances Kitchen
Appliances Laundry
(Note: The other top level categories do not have subcategories defined)
What is required of the SQL data view is to provide both name and
category_id for each distinct CATEGORY and SUBCATEGORY (see example below).
That specifically requires that each top level CATEGORY be listed explicitly
,
and each CATEGORY that does have an associated SUBCATEGORY will also need to
be listed (with names concatenated with hyphen as example below) both withou
t
its associated SUBCATEGORY records and with the associated SUBCATEGORY
records (along with its specific category_id unique identifier). Using the
two datasets above the required output of the data view would be as follows:
Concatenated Name Category_id
Foundation {QDEP74849393939303020}
Slab {BNIO802274939302020207}
Rough Shell {UUED34128554488326264} ? (Note here the top level category
is
listed in addition to its related records)
Rough Shell – Framing {HGKJ556388920118933933}
Rough Shell – Windows {LLPU112331099789875542}
Rough Shell – Doors {YVXX777546752211456023}
Mechanicals {DSFD44322274747299844}
Finish Trades {SSWQ43271727300998112}
Appliances {MYYB986373722924848433}
(Note here the top level category
is listed in addition to its related records)
Appliances – Kitchen {EEIU009833551238700909}
Appliances – Laundry (VVVC032327659302846593}
Thanks for your help.
Regards,
DonTest this:
SELECT name, category_id FROM Category
UNION
(SELECT LTRIM(RTRIM(a.name))+' - '+LTRIM(RTRIM(b.name)) AS name, b.category_
id
FROM Category a JOIN Subcategory b ON a.category_id = b.parent_id)
ORDER BY name
"dbj" wrote:

> The objective here is to create a SQL data view of two tables that have a
one
> to many relationship. The two tables represent a simple category/subcateg
ory
> relationship and the common value that will need to be returned will be th
e
> name and its primary key (unique identifier). Let me represent the desire
d
> result by the following example.
> This represents the table/field schema:
> TABLE 1 – CATEGORY
> category_id
> name
> TABLE 2 – SUBCATEGORY
> category_id
> name
> parent_id (relates to category_id in TABLE 1- CATEGORY)
>
> The following represents the top level CATEGORY sample data:
> TABLE 1 – CATEGORY
> Name
> Foundation
> Slab
> Rough Shell
> Mechanicals
> Finish Trades
> Appliances
> The second representation is the related SUBCATEGORY sample data:
> TABLE 1 – SUBCATEGORY
> Parent_Name Name
> Rough Shell Framing
> Rough Shell Windows
> Rough Shell Doors
> Appliances Kitchen
> Appliances Laundry
> (Note: The other top level categories do not have subcategories defined)
> What is required of the SQL data view is to provide both name and
> category_id for each distinct CATEGORY and SUBCATEGORY (see example below)
.
> That specifically requires that each top level CATEGORY be listed explicit
ly,
> and each CATEGORY that does have an associated SUBCATEGORY will also need
to
> be listed (with names concatenated with hyphen as example below) both with
out
> its associated SUBCATEGORY records and with the associated SUBCATEGORY
> records (along with its specific category_id unique identifier). Using th
e
> two datasets above the required output of the data view would be as follow
s:
> Concatenated Name Category_id
> Foundation {QDEP74849393939303020}
> Slab {BNIO802274939302020207}
> Rough Shell {UUED34128554488326264} ? (Note here the top level categor
y is
> listed in addition to its related records)
> Rough Shell – Framing {HGKJ556388920118933933}
> Rough Shell – Windows {LLPU112331099789875542}
> Rough Shell – Doors {YVXX777546752211456023}
> Mechanicals {DSFD44322274747299844}
> Finish Trades {SSWQ43271727300998112}
> Appliances {MYYB986373722924848433}
(Note here the top level catego
ry
> is listed in addition to its related records)
> Appliances – Kitchen {EEIU009833551238700909}
> Appliances – Laundry (VVVC032327659302846593}
> Thanks for your help.
> Regards,
> Don
>|||Worked like a charm. Thanks very much!!!
Don
"Mihaly" <Mihaly@.discussions.microsoft.com> wrote in message
news:52BB0F34-E93A-40BC-BB75-B9A9A765B52F@.microsoft.com...
> Test this:
> SELECT name, category_id FROM Category
> UNION
> (SELECT LTRIM(RTRIM(a.name))+' - '+LTRIM(RTRIM(b.name)) AS name,
> b.category_id
> FROM Category a JOIN Subcategory b ON a.category_id = b.parent_id)
> ORDER BY name
>
> "dbj" wrote:
>