2010-08-20 4 views
0

SQL Server 2008 R2 데이터베이스에서 이것은 매우 어려운 문제입니다. NotificationTemplate 0에서 많은 NotificationSmsTemplate SMS는 메시지를 160 자로 제한하기 때문에 자식 SMS는 전체 SMS 통신을 전달하기 위해 여러 SMS를 순서대로 보내야합니다. Per NotificationTemplate, 각 NotificationSmsTemplate에는 SmsSequenceNumber 속성이 있습니다. 이 번호는 고유 한 것으로서 NotificationTemplate을 포함하는 한 어떤 것이 될 수 있습니다.자식 레코드의 시퀀스 번호가 1에서 시작하는지 확인하십시오.

어떻게 시퀀스 번호가 1 일을 시작하고 포함 NotificationTemplate에 대한 NotificationSmsTemplate 개체의 컬렉션 이리저리 연속 것을 보장 할 수 있습니다. 나는 내부 시퀀스 번호를 사용하여 사용자가 화면에 템플릿을 주문한 다음 DB에 삽입하는 동안 가시 순서 번호를 생성하여 순서를 지정할 수 있도록 생각할 수 있습니다.

+0

어떤 DBMS를 사용하십니까? – Mike

답변

1

필자가 요구 사항을 올바르게 이해했다면, AUTO_INCREMENT 컬럼이 MyISAM 테이블의 다중 컬럼 인덱스의 일부일 때 MySQL이 AUTO_INCREMENT 값을 재사용하는 방식을 활용할 수 있습니다. 자세한 내용은 Using AUTO_INCREMENT을 참조하십시오.

CREATE TABLE IF NOT EXISTS `notification_sms_template` (
    `notification_template_id` INT NOT NULL , 
    `sms_sequence_number` INT NOT NULL AUTO_INCREMENT , 
    `sms` VARCHAR(160) NOT NULL , 
    PRIMARY KEY (`notification_template_id`, `sms_sequence_number`)) 
ENGINE = MyISAM; 

삽입 :

CREATE TABLE IF NOT EXISTS `notification_template` (
    `id` INT NOT NULL AUTO_INCREMENT , 
    `notification` TEXT NOT NULL , 
    PRIMARY KEY (`id`)) 
ENGINE = MyISAM; 

는 SMS 템플릿을 저장할 테이블을 만듭니다

이 알림 템플릿을 저장할 테이블 만들기 : 여기

무슨 뜻인지 설명하기 위해 예입니다 notification_template 테이블에 긴 텍스트 한 쌍을 입력하십시오 :

INSERT INTO `notification_template` (`id`, `notification`) VALUES 
(1, 'Tell me, O Muse, of that ingenious hero who travelled far and wide after he had sacked the famous town of Troy. Many cities did he visit, and many were the nations with whose manners and customs he was acquainted; moreover he suffered much by sea while trying to save his own life and bring his men safely home; but do what he might he could not save his men, for they perished through their own sheer folly in eating the cattle of the Sun-god Hyperion; so the god prevented them from ever reaching home. Tell me, too, about all these things, oh daughter of Jove, from whatsoever source you may know them.'), 
(2, 'There were once a man and a woman who had long in vain wished for a child. At length the woman hoped that God was about to grant her desire. These people had a little window at the back of their house from which a splendid garden could be seen, which was full of the most beautiful flowers and herbs. It was, however, surrounded by a high wall, and no one dared to go into it because it belonged to an enchantress, who had great power and was dreaded by all the world.'); 

가 지정하는 notification_sms_template 테이블에 160 개 문자 청크를 삽입 notification_templateid은 그들이 관계하는 : 당신은 지금 notification_sms_template에서 ID를 선택하면

INSERT INTO `notification_sms_template` (`notification_template_id`, `sms`) VALUES 
(1, 'Tell me, O Muse, of that ingenious hero who travelled far and wide after he had sacked the famous town of Troy. Many cities did he visit, and many were the nat'), 
(1, 'ions with whose manners and customs he was acquainted; moreover he suffered much by sea while trying to save his own life and bring his men safely home; but do'), 
(1, ' what he might he could not save his men, for they perished through their own sheer folly in eating the cattle of the Sun-god Hyperion; so the god prevented th'), 
(1, 'em from ever reaching home. Tell me, too, about all these things, oh daughter of Jove, from whatsoever source you may know them.'), 
(2, 'There were once a man and a woman who had long in vain wished for a child. At length the woman hoped that God was about to grant her desire. These people had a'), 
(2, ' little window at the back of their house from which a splendid garden could be seen, which was full of the most beautiful flowers and herbs. It was, however, '), 
(2, 'surrounded by a high wall, and no one dared to go into it because it belonged to an enchantress, who had great power and was dreaded by all the world.'); 

, 당신은 볼 것이다 1에서 sms_sequence_number 시작 각 notification_template :

SELECT `notification_template_id`, `sms_sequence_number` 
FROM `notification_sms_template`; 

+--------------------------+---------------------+ 
| notification_template_id | sms_sequence_number | 
+--------------------------+---------------------+ 
|      1 |     1 | 
|      1 |     2 | 
|      1 |     3 | 
|      1 |     4 | 
|      2 |     1 | 
|      2 |     2 | 
|      2 |     3 | 
+--------------------------+---------------------+ 
+0

+1 정보가 있지만 SQL Server 2008을 사용하고 있습니다. 죄송 합니다만 언급하지는 않았지만 지금 수정하여 추가했습니다. – ProfK

+0

@ProfK : 아 글쎄, 시도 가치 ;-) – Mike

+0

대단한 가치가 있습니다. 일부 프로젝트에서는 MySQL을 사용합니다. – ProfK

관련 문제