Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change/alter table schema 2

Status
Not open for further replies.

sparkbyte

Technical User
Sep 20, 2002
879
US
in SQL2005 how to you change a table's schema?


say table employee was originally created as thus.

Code:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tblEmployee](
	[EmployeePK] [int] IDENTITY(1,1) NOT NULL,
	[EmployeeID] [varchar](15) NOT NULL,
	[EmployeeFN] [varchar](25) NULL,
	[EmployeeMI] [varchar](25) NULL,
	[EmployeeLN] [varchar](25) NULL,
	[EmployeeGen] [varchar](10) NULL,
	[EmployeeDept] [nvarchar](50) NULL,
	[EmployeeDateAdded] [datetime] NOT NULL CONSTRAINT [DF_tblEmployee_EmployeeDateAdded]  DEFAULT (getdate()),
	[EmployeeDateDeleted] [datetime] NULL,
	[EmployeeRemovedBy] [varchar](15) NULL,
 CONSTRAINT [PK_tblEmployee] PRIMARY KEY CLUSTERED 
(
	[EmployeePK] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF

and shows up as dbo.tblEmployee

What I want to do is begin to alter the database schema (in a developement environment) so that dbo.tblEmployee would be common.tblEmployee and so forth to see how it will effect the UI and hopefully allow better overall security.

Thanks

John Fuhrman
 
Create Schema common AUTHORIZATION dbo
go
alter schema dbo Transfer common.tblTrackingTable


New schema creted OK but the tblTrackingTable did not change to the newly created schema.

Thanks

John Fuhrman
 
Sorry the erro is below.

Msg 15151, Level 16, State 1, Line 1
Cannot find the object 'tblTrackingTable', because it does not exist or you do not have permission.


it should not be permissions as I am dbo.



Thanks

John Fuhrman
 
You need to do it the opposite way. See the example

USE AdventureWorks2008R2;
GO
ALTER SCHEMA HumanResources TRANSFER Person.Address;
GO

So,

try

Code:
alter schema Common Transfer dbo.tblTrackingTable

PluralSight Learning Library
 
I see says the blind man.........

gave each a star since both answers were correct.

Thanks

Thanks

John Fuhrman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top