|
이 문서는 수동으로 번역한 것입니다. 원본 텍스트를 보려면 포인터를 문서의 문장 위로 올리십시오.
|
번역
원본
|
sp_rename(Transact-SQL)
주의
|
|---|
|
|
1.테이블 이름 바꾸기
USE AdventureWorks2012; GO EXEC sp_rename 'Sales.SalesTerritory', 'SalesTerr'; GO
2.열 이름 바꾸기
USE AdventureWorks2012; GO EXEC sp_rename 'Sales.SalesTerritory.TerritoryID', 'TerrID', 'COLUMN'; GO
3.인덱스 이름 바꾸기
USE AdventureWorks2012; GO EXEC sp_rename N'Purchasing.ProductVendor.IX_ProductVendor_VendorID', N'IX_VendorID', N'INDEX'; GO
4.별칭 데이터 형식 이름 바꾸기
USE AdventureWorks2012; GO EXEC sp_rename N'Phone', N'Telephone', N'USERDATATYPE'; GO
5.제약 조건 이름 바꾸기
USE AdventureWorks2012;
GO
-- Return the current Primary Key, Foreign Key and Check constraints for the Employee table.
SELECT name, SCHEMA_NAME(schema_id) AS schema_name, type_desc
FROM sys.objects
WHERE parent_object_id = (OBJECT_ID('HumanResources.Employee'))
AND type IN ('C','F', 'PK');
GO
-- Rename the primary key constraint.
sp_rename 'HumanResources.PK_Employee_BusinessEntityID', 'PK_EmployeeID';
GO
-- Rename a check constraint.
sp_rename 'HumanResources.CK_Employee_BirthDate', 'CK_BirthDate';
GO
-- Rename a foreign key constraint.
sp_rename 'HumanResources.FK_Employee_Person_BusinessEntityID', 'FK_EmployeeID';
-- Return the current Primary Key, Foreign Key and Check constraints for the Employee table.
SELECT name, SCHEMA_NAME(schema_id) AS schema_name, type_desc
FROM sys.objects
WHERE parent_object_id = (OBJECT_ID('HumanResources.Employee'))
AND type IN ('C','F', 'PK');
name schema_name type_desc ------------------------------------- ------------------ ---------------------- FK_Employee_Person_BusinessEntityID HumanResources FOREIGN_KEY_CONSTRAINT PK_Employee_BusinessEntityID HumanResources PRIMARY_KEY_CONSTRAINT CK_Employee_BirthDate HumanResources CHECK_CONSTRAINT CK_Employee_MaritalStatus HumanResources CHECK_CONSTRAINT CK_Employee_HireDate HumanResources CHECK_CONSTRAINT CK_Employee_Gender HumanResources CHECK_CONSTRAINT CK_Employee_VacationHours HumanResources CHECK_CONSTRAINT CK_Employee_SickLeaveHours HumanResources CHECK_CONSTRAINT (7 row(s) affected) name schema_name type_desc ------------------------------------- ------------------ ---------------------- FK_Employee_ID HumanResources FOREIGN_KEY_CONSTRAINT PK_Employee_ID HumanResources PRIMARY_KEY_CONSTRAINT CK_BirthDate HumanResources CHECK_CONSTRAINT CK_Employee_MaritalStatus HumanResources CHECK_CONSTRAINT CK_Employee_HireDate HumanResources CHECK_CONSTRAINT CK_Employee_Gender HumanResources CHECK_CONSTRAINT CK_Employee_VacationHours HumanResources CHECK_CONSTRAINT CK_Employee_SickLeaveHours HumanResources CHECK_CONSTRAINT (7 row(s) affected)
6.통계 이름 바꾸기
CREATE STATISTICS ContactMail1
ON Person.Person (BusinessEntityID, EmailPromotion)
WITH SAMPLE 5 PERCENT;
sp_rename 'Person.Person.ContactMail1', 'NewContact','Statistics';

주의