Monday, March 19, 2012
Deleting a range of tables
Let me explain:
SERVER1 Tables (AAA010, AAA020, AAA040, AAA080, AAA090)
SERVER2 Tables (AAA010, AAA020, AAA040, AAA080, AAA090)
I need to transfer JUST the '%040' and '%080' tables from the SERVER2 to SERVER1.
It could be easy if was just 5 tables within each server, but are 1000+, AAA, AAB,...,XXX, XXZ.
Someone has a script to transfer only the marked tables ('%040') or to drop just the other tables ? How can i make this without selecting one by one the tables in the 'select the tables to transfer' option in sql enterprise manager ?
thankx !
ps. sorry for my english, i'm brazilian, i hope u understand...I don't know DTS well enough to provide an example but back in my Ingress days I had to move data between servers, not always the same servers and not always the same tables. My solution was to create a table that would hold information on the source and target server(s) and database(s) involved in the transfer.
My script would loop through the table selecting server pairs and then loop through the tables to be processed. As I recall it was a simple matter to process a list of tables or a description, '%020','%040'.
I don't know if this helps you or not. I will look through the documentation on DTS and see if I can come up with an example.
Sunday, February 19, 2012
delete records ?
Hello, its hard to explain, i have a table like this:
--userpage_visitors--
id bigint
owner nvarchar(20)
visitor nvarchar(20)
created datetime
Then i have some code like this: (@.Visitor is send to the stored proc)
DECLARE @.lastusernvarchar(20)
SELECTTOP 1 @.lastuser= visitorFROM userpage_visitorsWHERE(owner= @.UserName)ORDERBY createdDESC
IF(@.lastuser<> @.Visitor)
BEGIN
INSERTINTO userpage_visitors(owner, visitor, created)VALUES(@.UserName, @.Visitor, @.Created)
-- delete here
END
Now after i have inserted the new visitor into the table, i need to clean the table... so each user should have maximum of 30 visitors, so if the user i inserted above is the 31st user then i need to delete the first user, so i always have 30 fresch visitors,, if they have less then 30 visitors then nothing should happen. The question is, how can i get the 31th post? in mysql you can say that you want post 30, 31, but in mssql you only have the TOP to select limited posts, any ideas?
Patrick
In Sql 2005 you can actually select limited records using Row_Number()But what you need to do is where you have marked -- delete here
IF (SELECT COUNT(ID) FROM Userpage_Visitors ) > 30
BEGIN
DELETE FROM Userpage_Visitors WHERE ID = (SELECT TOP 1 ID FROM Userpage_Visitors ORDER BY Created)
END
That will delete the oldest entry in the table