Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Create FirstName and LastName to Replace Existing FirstName and LastName Expand / Collapse
Author
Message
Posted Tuesday, June 4, 2013 5:50 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, September 11, 2014 3:32 PM
Points: 977, Visits: 3,357
Hello Everyone
I hope that you all are having a very nice day.

I am wanting to change all the FirstName and LastName values in a table. This is more for Demo security really. Creating some fake names from existing names. These are stored in two separate columns. I cannot think of any way to easily do this. I need approx 25,000 rows. LOL There are names in the columns currently, I would just like to change them so that the entire record does not show an actual person. I want to use real names, not anything like FirstName1, FirstName2, etc....

So Frank Smith, would be changed to Joe Jackson

I have already changed all the dates and numeric values, those were simple.

I greatly appreciate any and all assistance, suggestions and comments.

Thanks
Andrew SQLDBA
Post #1459996
Posted Tuesday, June 4, 2013 6:02 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 9:48 PM
Points: 3,636, Visits: 8,151
How about using names from AdventureWorks DB?


Luis C.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1459998
Posted Tuesday, June 4, 2013 6:14 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 9:48 PM
Points: 3,636, Visits: 8,151
Maybe some code like this

SELECT FirstName, LastName
FROM(
SELECT FirstName,
ROW_NUMBER() OVER(ORDER BY FirstName) rn
FROM( SELECT DISTINCT FirstName FROM MyTable)x) a
JOIN (
SELECT LastName,
ROW_NUMBER() OVER(ORDER BY LastName DESC) rn
FROM( SELECT DISTINCT LastName FROM MyTable)y ) b ON a.rn = b.rn





Luis C.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1459999
Posted Tuesday, June 4, 2013 8:47 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: 2 days ago @ 11:51 AM
Points: 1,040, Visits: 3,106
Here's another option
with sampleData as (
SELECT FirstName, LastName, ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) N
FROM (VALUES
('Robin','Bacon'),
('Owen','Twomey'),
('James','Kendall'),
('John','Cavanagh'),
('Lola','Oxborough'),
('Thomas','Archibald'),
('Mathias','Kearns'),
('Christine','Winger'),
('Barry','Kane'),
('Rereahu','Gray'),
('Douglas','Christian'),
('Jennifer','Clark'),
('Kenneth','Court'),
('Paul','Pedersen'),
('Bruce','McKelvie'),
('David','McCrary'),
('Paul','Allison'),
('Linda','Cawthorn'),
('Noelene','Schellhorn'),
('Patricia','Pedersen'),
('Ivan','Hill'),
('Stewart','Leys'),
('James','Austin'),
('Roger','McManaway'),
('Katherine','Edmonds'),
('Bryan','Wilson'),
('James','Jones'),
('William','Healey'),
('Caroline','Rae'),
('Stephen','Mullins'),
('Graeme','Gray'),
('Gary','Gibbens'),
('Annie','Oxborough'),
('Emma','Kennedy'),
('Patricia','Wii'),
('Raymond','Winger'),
('Judith','Owen'),
('Ruby','McCrary'),
('Peter','Waterhouse'),
('Gaye','Cox'),
('Barbara','Hill'),
('Jeanette','Patchett'),
('Norman','Forbes'),
('Andrew','Forsyth'),
('Aldyth','Edmonds'),
('Mick','Stohr'),
('Nicola','Howie'),
('Linda','Gray'),
('Fenella','Silva'),
('Allan','McCandless'),
('Gillian','Scott'),
('Garth','Woodcock'),
('Peter','Woodcock'),
('Fenella','Waterhouse'),
('Patricia','Leys'),
('Paul','Sykes'),
('Richard','Fortzer'),
('Dean','McKelvie'),
('Cuan','Fortzer'),
('Vaughan','Heymons'),
('Donald','Toseland'),
('Alan','Sclater'),
('Nancy','Ollerenshaw'),
('Eddie','Buhler'),
('Lewis','Taylor'),
('Kerin','Medland'),
('Carlton','Forsyth-King'),
('Opie','Cleland'),
('Gail','Oshannessy'),
('Stuart','Gray')
) AS N (FirstName, LastName)
)
,RandFirstName AS (SELECT FirstName, ROW_NUMBER() OVER (ORDER BY RAND(CAST(NEWID() AS VARBINARY))) N FROM sampledata a)
,RandLastName AS (SELECT LastName, ROW_NUMBER() OVER (ORDER BY RAND(CAST(NEWID() AS VARBINARY))) N FROM sampledata a)
SELECT f.FirstName, l.LastName, a.FirstName, a.LastName
FROM sampledata a
INNER JOIN RandFirstName f ON a.N = f.N
INNER JOIN RandLastName l ON a.N = l.N;

Sample data was pre randomized, but it still came up with a name of someone I know Fortunately he wasn't in the original list.

Edit: Just tested this over around 500,000 rows and had it return 1 or 2 non randomized names 6 out 10 times. They were generally common names though, eg John Smith
Post #1460013
Posted Wednesday, June 5, 2013 8:32 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 3:59 PM
Points: 13,007, Visits: 12,426
Or use any of the free fake name generators on the interwebz. Here is one I have used in the past, there are plenty of others.

http://homepage.net/name_generator/


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1460255
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse