|
이 문서는 수동으로 번역한 것입니다. 원본 텍스트를 보려면 포인터를 문서의 문장 위로 올리십시오. 추가 정보
|
번역
원본
|
CREATE SYNONYM(Transact-SQL)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 로컬 및 전역 임시 테이블이 포함됩니다.
1.로컬 개체의 동의어 만들기
USE tempdb; GO -- Create a synonym for the Product table in AdventureWorks2012. CREATE SYNONYM MyProduct FOR AdventureWorks2012.Production.Product; GO -- Query the Product table by using the synonym. USE tempdb; GO SELECT ProductID, Name FROM MyProduct WHERE ProductID < 5; GO
결과 집합은 다음과 같습니다.
-----------------------
ProductID Name
----------- --------------------------
1 Adjustable Race
2 Bearing Ball
3 BB Ball Bearing
4 Headset Ball Bearings
(4 row(s) affected)
2.원격 개체의 동의어 만들기
EXEC sp_addlinkedserver Server_Remote; GO USE tempdb; GO CREATE SYNONYM MyEmployee FOR Server_Remote.AdventureWorks2012.HumanResources.Employee; GO
3.사용자 정의 함수의 동의어 만들기
-- Creating the dbo.OrderDozen function CREATE FUNCTION dbo.OrderDozen (@OrderAmt int) RETURNS int WITH EXECUTE AS CALLER AS BEGIN IF @OrderAmt % 12 <> 0 BEGIN SET @OrderAmt += 12 - (@OrderAmt % 12) END RETURN(@OrderAmt); END; GO -- Using the dbo.OrderDozen function DECLARE @Amt int SET @Amt = 15 SELECT @Amt AS OriginalOrder, dbo.OrderDozen(@Amt) AS ModifiedOrder -- Create a synonym dbo.CorrectOrder for the dbo.OrderDozen function. CREATE SYNONYM dbo.CorrectOrder FOR dbo.OrderDozen; GO -- Using the dbo.CorrectOrder synonym. DECLARE @Amt int SET @Amt = 15 SELECT @Amt AS OriginalOrder, dbo.CorrectOrder(@Amt) AS ModifiedOrder