Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
getur.srikanth@gmail.com
Yak Posting Veteran
77 Posts |
Posted - 2009-10-06 : 10:40:21
|
I am getting Caution while running below SP. I dont understand problem."Caution: Changing any part of an object name could break scripts and stored procedures.Caution: Changing any part of an object name could break scripts and stored procedures."set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgoALTER PROCEDURE [dbo].[LOAD_ORG_MEMBERS] ASBEGIN SET NOCOUNT ON; if exists (select * from dbo.sysobjects where id = object_id(N'[ORG_MEMBERS_OLD]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [ORG_MEMBERS_OLD] if exists (select * from dbo.sysobjects where id = object_id(N'[TEMP_ORG_MEMBERS]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [TEMP_ORG_MEMBERS] CREATE TABLE [TEMP_ORG_MEMBERS]( [CONSTIT_ID] [char](10) NOT NULL, [SORT_NAME] [varchar](200) NULL, [FULLNAME] [varchar](200) NULL, [LASTNAME] [varchar](200) NULL, [FIRSTNAME] [varchar](200) NULL, [MIDDLENAME] [varchar](200) NULL, [BIRTHDATE] [varchar](50) NULL, [BUSINESS_PHONE] [varchar](100) NULL, [HOME_PHONE] [varchar](100) NULL, [FAX] [varchar](100) NULL, [OTHER_PHONE] [varchar](100) NULL, [CELL_PHONE] [varchar](100) NULL, [ADDRESS1] [varchar](200) NULL, [ADDRESS2] [varchar](200) NULL, [ADDRESS3] [varchar](200) NULL, [CITY] [varchar](100) NULL, [STATE] [varchar](100) NULL, [POSTAL_CODE] [varchar](100) NULL, [COUNTRY] [varchar](100) NULL, [EMAIL_ADDRESS] [varchar](250) NULL, [DUES] [varchar](25) NULL, [MEMBERSINCE] [varchar](50) NULL, [COMPANY_NAME] [varchar](250) NULL, [TITLE] [varchar](250) NULL, [SECTION] [varchar](250) NULL, [PRIMARYTECHDISC] [varchar](250) NULL, [ACCOUNTNAME] [varchar](250) NULL) ON [PRIMARY] -- Insert statements for procedure here INSERT INTO [TEMP_ORG_MEMBERS] ([CONSTIT_ID] ,[SORT_NAME] ,[FULLNAME] ,[LASTNAME] ,[FIRSTNAME] ,[MIDDLENAME] ,[BIRTHDATE] ,[BUSINESS_PHONE] ,[HOME_PHONE] ,[FAX] ,[OTHER_PHONE] ,[CELL_PHONE] ,[ADDRESS1] ,[ADDRESS2] ,[ADDRESS3] ,[CITY] ,[STATE] ,[POSTAL_CODE] ,[COUNTRY] ,[EMAIL_ADDRESS] ,[DUES] ,[MEMBERSINCE] ,[COMPANY_NAME] ,[TITLE] ,[SECTION] ,[PRIMARYTECHDISC] ,[ACCOUNTNAME]) (SELECT * FROM OPENQUERY(PROD,'select distinct m.u##CONSTIT_ID, m.SORT_NAME, c.IN_LABELNAME, c.LASTNAME, case when trim(c.nickname) is not null then c.nickname else c.firstname end as firstname, c.MI, TO_CHAR(c.birth_dt,''DD-MON''), c.phone1 as business_phone, c.phone2 as home, c.phone3 as fax, c.phone4 as alt_home, c.phone5 as cell, a.addr_attn, a.ADDR_LINE1, a.ADDR_LINE2, a.CITY, a.STATE, a.ZIP, a.COUNTRY, e.E_ADDR, DECODE (m.paid_in_full,1,''Paid'',''Unpaid'') as Paid, TO_CHAR(m.JOIN_DT,''DD-MON-YYYY''), c.CO_FULLNAME, c.indiv_title, m1.section_name, c1.CODE_DESC, ''AspNetSqlMembershipProvider:''||m.u##constit_idfrom MI.MBMEMBER m,MI.CONSTIT c,MI.EADDRESS e,MI.ADDRESS a,(select m2.u##constit_id, s.section_name from MI.mbmember m2, MI.mbsecreg s wherem2.u##class_code = ''SECTION'' and m2.u##code_value = s.u##sectionand m2.start_dt <= SYSDATEand m2.end_dt >= SYSDATEand m2.cancel_dt is nulland m2.cancel_reason = '' ''and m2.u##member_type = ''PRIMARY'') m1,(select c2.u##constit_id, t.code_desc from MI.cncatcod c2, MI.CNCODTAB t where t.u##cat_code = ''SCLVL1PRIM''and c2.u##cat_code = t.u##cat_codeand c2.u##code_value = t.u##code_value) c1where m.u##class_code = ''ORG''and m.start_dt <= SYSDATEand m.end_dt >= SYSDATEand m.u##constit_id = c.u##constit_idand m.u##constit_id = e.u##constit_idand m.u##constit_id = m1.u##constit_id (+)and e.u##e_label=''EMAIL''and e.e_default = 1and m.u##mail_iaid = a.u##iaidand m.cancel_dt is nulland m.cancel_reason = '' ''and m.u##CONSTIT_ID = c1.u##constit_id (+)'));EXEC SP_RENAME 'ORG_MEMBERS', 'ORG_MEMBERS_OLD'EXEC SP_RENAME 'TEMP_ORG_MEMBERS', 'ORG_MEMBERS' END |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-10-06 : 10:41:12
|
| Its the rename at the end of the procedure, it is just an informational message as you are changing the names of objects. |
 |
|
|
getur.srikanth@gmail.com
Yak Posting Veteran
77 Posts |
Posted - 2009-10-06 : 10:52:53
|
| I want keep this SP in Schedule task. Will this cause any problem ? Will it break SP.? |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-10-06 : 10:56:47
|
| No, as I said, it is just an informational message, it doesn't mean it failed. |
 |
|
|
getur.srikanth@gmail.com
Yak Posting Veteran
77 Posts |
Posted - 2009-10-06 : 11:07:24
|
| Thanks for your info |
 |
|
|
asgast
Posting Yak Master
149 Posts |
Posted - 2009-10-06 : 11:17:12
|
| you don't go playing with tables like this on sql servermake 2 tablesin the begining of procedure truncate the data from the _old onerepopulate the ORG_MEMBERS tablewill work faster, will work much stableCan't fall asleep, the ghost of sql server will get me for writing bad queries. Have to stay awake ... |
 |
|
|
getur.srikanth@gmail.com
Yak Posting Veteran
77 Posts |
Posted - 2009-10-07 : 11:01:57
|
asgast-Can you please showme steps that I need to create tables and truncate data and repoplate into ORG_MEMBERS quote: Originally posted by asgast you don't go playing with tables like this on sql servermake 2 tablesin the begining of procedure truncate the data from the _old onerepopulate the ORG_MEMBERS tablewill work faster, will work much stableCan't fall asleep, the ghost of sql server will get me for writing bad queries. Have to stay awake ...
|
 |
|
|
asgast
Posting Yak Master
149 Posts |
Posted - 2009-10-07 : 11:24:39
|
| create the tables ORG_MEMBERS and ORG_MEMBERS_OLD before running a procedureset ANSI_NULLS ONset QUOTED_IDENTIFIER ONgoALTER PROCEDURE [dbo].[LOAD_ORG_MEMBERS] ASBEGINTRUNCATE TABLE ORG_MEMBERS_OLD /*here we empty the _old table*//*put the data from ORG_MEMBERS into ORG_MEMBERS _old*/INSERT ORG_MEMBERS_OLD( CONSTIT_ID, SORT_NAME, FULLNAME, LASTNAME, FIRSTNAME, MIDDLENAME, BIRTHDATE ,BUSINESS_PHONE, HOME_PHONE, FAX, OTHER_PHONE, CELL_PHONE, ADDRESS1, ADDRESS2, ADDRESS3 ,CITY, STATE, POSTAL_CODE, COUNTRY, EMAIL_ADDRESS, DUES, MEMBERSINCE, COMPANY_NAME, TITLE, SECTION, PRIMARYTECHDISC, ACCOUNTNAME)SELECT CONSTIT_ID, SORT_NAME, FULLNAME, LASTNAME, FIRSTNAME, MIDDLENAME, BIRTHDATE ,BUSINESS_PHONE, HOME_PHONE, FAX, OTHER_PHONE, CELL_PHONE, ADDRESS1, ADDRESS2, ADDRESS3 ,CITY, STATE, POSTAL_CODE, COUNTRY, EMAIL_ADDRESS, DUES, MEMBERSINCE, COMPANY_NAME, TITLE, SECTION, PRIMARYTECHDISC, ACCOUNTNAMEFROM ORG_MEMBERSTRUNCATE TABLE ORG_MEMBERS /*empty ORG_MEMBERS table*//*repopulate it*/ INSERT INTO [TEMP_ORG_MEMBERS] ([CONSTIT_ID] ,[SORT_NAME] ,[FULLNAME] ,[LASTNAME] ,[FIRSTNAME] ,[MIDDLENAME] ,[BIRTHDATE] ,[BUSINESS_PHONE] ,[HOME_PHONE] ,[FAX] ,[OTHER_PHONE] ,[CELL_PHONE] ,[ADDRESS1] ,[ADDRESS2] ,[ADDRESS3] ,[CITY] ,[STATE] ,[POSTAL_CODE] ,[COUNTRY] ,[EMAIL_ADDRESS] ,[DUES] ,[MEMBERSINCE] ,[COMPANY_NAME] ,[TITLE] ,[SECTION] ,[PRIMARYTECHDISC] ,[ACCOUNTNAME]) (SELECT * FROM OPENQUERY(PROD,'select distinct m.u##CONSTIT_ID, m.SORT_NAME, c.IN_LABELNAME, c.LASTNAME, case when trim(c.nickname) is not null then c.nickname else c.firstname end as firstname, c.MI, TO_CHAR(c.birth_dt,''DD-MON''), c.phone1 as business_phone, c.phone2 as home, c.phone3 as fax, c.phone4 as alt_home, c.phone5 as cell, a.addr_attn, a.ADDR_LINE1, a.ADDR_LINE2, a.CITY, a.STATE, a.ZIP, a.COUNTRY, e.E_ADDR, DECODE (m.paid_in_full,1,''Paid'',''Unpaid'') as Paid, TO_CHAR(m.JOIN_DT,''DD-MON-YYYY''), c.CO_FULLNAME, c.indiv_title, m1.section_name, c1.CODE_DESC, ''AspNetSqlMembershipProvider:''||m.u##constit_idfrom MI.MBMEMBER m,MI.CONSTIT c,MI.EADDRESS e,MI.ADDRESS a,(select m2.u##constit_id, s.section_name from MI.mbmember m2, MI.mbsecreg s wherem2.u##class_code = ''SECTION'' and m2.u##code_value = s.u##sectionand m2.start_dt <= SYSDATEand m2.end_dt >= SYSDATEand m2.cancel_dt is nulland m2.cancel_reason = '' ''and m2.u##member_type = ''PRIMARY'') m1,(select c2.u##constit_id, t.code_desc from MI.cncatcod c2, MI.CNCODTAB t where t.u##cat_code = ''SCLVL1PRIM''and c2.u##cat_code = t.u##cat_codeand c2.u##code_value = t.u##code_value) c1where m.u##class_code = ''ORG''and m.start_dt <= SYSDATEand m.end_dt >= SYSDATEand m.u##constit_id = c.u##constit_idand m.u##constit_id = e.u##constit_idand m.u##constit_id = m1.u##constit_id (+)and e.u##e_label=''EMAIL''and e.e_default = 1and m.u##mail_iaid = a.u##iaidand m.cancel_dt is nulland m.cancel_reason = '' ''and m.u##CONSTIT_ID = c1.u##constit_id (+)'));ENDCan't fall asleep, the ghost of sql server will get me for writing bad queries. Have to stay awake ... |
 |
|
|
asgast
Posting Yak Master
149 Posts |
Posted - 2009-10-07 : 11:31:24
|
| you need to keep in mind, that in order to be able to trancate table you need alter permissions on it, this command renews the table (identity values resets, data deletes) truncate goes into logs as 1 statement, works faster then deleteif you want you can use DELETE FROM instead of TRUNCATE TABLEI don't understand, what are you doing in open query?Can't fall asleep, the ghost of sql server will get me for writing bad queries. Have to stay awake ... |
 |
|
|
getur.srikanth@gmail.com
Yak Posting Veteran
77 Posts |
Posted - 2009-10-07 : 11:38:55
|
| Why I am using Open Query??? because PROD is Oracle database. I am pulling data from Oracle to SQL table.Small questing ?TRUNCATE TABLE ORG_MEMBERS /*empty ORG_MEMBERS table*//*repopulate it*/INSERT INTO [TEMP_ORG_MEMBERS] /* I think it should be INSERT INTO [ORG_MEMBERS] , Right?*/ |
 |
|
|
asgast
Posting Yak Master
149 Posts |
Posted - 2009-10-07 : 11:50:04
|
| Ohhh that explains a lot :) in sql 2005 ou can use INSERTwithout adding INTO, INTO is now optionalCan't fall asleep, the ghost of sql server will get me for writing bad queries. Have to stay awake ... |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2009-10-07 : 14:36:15
|
quote: Originally posted by asgast you don't go playing with tables like this on sql server<snip>
Do you have any reason/support why one shouldn't do this?I'm not saying I disagree with you. But, I have seen instances where a database was available for end users to run reports against and reloading tables with 100's of millions of rows took some time and the creator of that database choose to employ a method similar to this that loaded a temporary table then dropped the existing table and renamed the temporary table so that users could continue to execute queries without having to wait for the table to finish loading.I changed the entire process so that only delta's were processed, and thus no need to reload the table every time, but truncating and reloading isn’t necessarily the best option either. |
 |
|
|
asgast
Posting Yak Master
149 Posts |
Posted - 2009-10-08 : 04:18:35
|
| Since I don't know what is the logic behind dropping out all the data at night and repopulating it from oracle server, I can't suggest how to rewrite this query for best. I can imagine a case where creating a temp table and replacing the old one with it would be better for user experience. And our example of 100m rows is one of them.It usually depends on the on site situations, what approach is best, I have found out that best practice is to start with standard: methods try them out and if they fail look for something different or not good enough.No need to reload the table completely would be the best solution. I suggested the same approach I have used in some cases. My table is much smaller than 100m. much smaller and I schedule repopulation at night, as I understand OP plans on doing something similar.I had a trouble once when I was switching tables and one of them was locked in a transaction, but it was a case of miscommunication with another developer.I suspect that your case things went like this:1 temporary page was build, and it took some time to do it, during the process users were accessing data in the main table, it took maybe an hour to gather all the data, no way we can leave users without info during that time2 a switch was made it took second to do it, speed of lightning compared to truncating and repopulating the old table.So getur.srikanth@gmail.com if your case looks like something from above, Lamprey is right and my approach is not the best. :) But I suspect that you are smart enough to notice.But if you work with small amounts I'd suggest you not to go around dropping and recreating tables.One more thing: somehow I must be living in another much advanced world, :) I expect people to understand what they are doing and that solution offered on the internet is not always a correct one.Can't fall asleep, the ghost of sql server will get me for writing bad queries. Have to stay awake ... |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-10-08 : 04:20:07
|
| In fact, I have just started working on a system like this. Loading is slow (mainly due to the hardware and the location of the offices), so the records are loaded into a temp even when there are deltas and then right at the end, the table is either renamed or a match that deletes any record in the live tab le that exist in the temp (due usually to users changing legacy data) and then copies the new records in at the last moment.There is nothing wrong per say with this (we are dealing with many millions of records), but it does take a bit of thinking about. |
 |
|
|
|
|
|
|
|