|
Dieser Artikel wurde manuell übersetzt. Bewegen Sie den Mauszeiger über die Sätze im Artikel, um den Originaltext anzuzeigen.
|
Übersetzung
Original
|
sp_rename (Transact-SQL)
Vorsicht
|
|---|
|
|
A.Umbenennen einer Tabelle
USE AdventureWorks2012; GO EXEC sp_rename 'Sales.SalesTerritory', 'SalesTerr'; GO
B.Umbenennen einer Spalte
USE AdventureWorks2012; GO EXEC sp_rename 'Sales.SalesTerritory.TerritoryID', 'TerrID', 'COLUMN'; GO
C.Umbenennen eines Indexes
USE AdventureWorks2012; GO EXEC sp_rename N'Purchasing.ProductVendor.IX_ProductVendor_VendorID', N'IX_VendorID', N'INDEX'; GO
D.Umbenennen eines Aliasdatentyps
USE AdventureWorks2012; GO EXEC sp_rename N'Phone', N'Telephone', N'USERDATATYPE'; GO
E.Umbenennen von Einschränkungen
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)
F.Umbenennen von Statistiken
CREATE STATISTICS ContactMail1
ON Person.Person (BusinessEntityID, EmailPromotion)
WITH SAMPLE 5 PERCENT;
sp_rename 'Person.Person.ContactMail1', 'NewContact','Statistics';

Vorsicht