김백일 님이 쓰신 글 :
: 초보자(우) 님이 쓰신 글 :
: : MS SQL은 자동으로 번호를 부여를 할 수있잔아요
: : IDENTITY 값을 주어서 데이터를 입력 할때 마다 생성이 되잔아요
: : 인터베이스에는 그런것이 엄나요
: : 아시는분 답변 쩜 부탁 합니다.
:
: 물론 가능합니다.
: 다음은 InterBase Tutorial에 있는 내용입니다. 참고하세요.
:
: ▶ Create a generator
:
: 1. Begin by checking the employee numbers in the Employee table, to confirm that the
: highest employee number currently in use is 145:
:
: SELECT emp_no from Employee
: ORDER BY emp_no
:
: Note: The statement above returns all the employee numbers so that you can confirm that 145 is the highest. The following statement produces the same information more efficiently:
:
: SELECT max(emp_no) from Employee
:
: 2. Triggers often use generators, and the trigger you create in the next exercise is an example of one. Execute the following statement to create a generator called emp_no_gen.
:
: CREATE GENERATOR emp_no_gen
:
: 3. Now initialize the generator to 145, the highest value currently in use.
:
: SET GENERATOR emp_no_gen TO 145
:
:
: ▶ Create a trigger that generates a value
:
: 1. The next statements define a trigger named set_emp_no that makes use of the
: emp_no_gen generator to generate unique sequential employee numbers and insert them
: into the Employee table.
:
: CREATE TRIGGER set_emp_no FOR Employee
: BEFORE INSERT AS
: BEGIN
: New.emp_no = gen_id(emp_no_gen, 1);
: END
:
: This statement says that the set_emp_no trigger will fire before an insert operation, and that it will create a new value for emp_no by calling the gen_id() function on the emp_no_gen generator with an increment of 1.
:
: 2. To test the generator, execute the following INSERT statement:
:
: INSERT INTO Employee (first_name, last_name, dept_no, job_code, job_grade,
: job_country, hire_date, salary, phone_ext)
: VALUES ('Reed', 'Richards', '671', 'Eng', 5, 'USA', '07/27/95', '34000', '444')
:
: Notice that you did not include a value for the emp_no column in the INSERT statement. Look at the new record by entering
:
: SELECT * from Employee WHERE last_name = 'Richards'
:
: The employee number is 146. Remember that the highest employee number before you created
: the generator and inserted a new row was 145. The trigger has automatically assigned the new
: employee the next employee number.
:
: 3. If your INSERT ran without errors and your SELECT returns the correct result set, commit
: your work.
:
|