Skip to content

Instantly share code, notes, and snippets.

@JamesSkemp
Last active October 19, 2020 14:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesSkemp/5a481d8c46dc4e7df3a7 to your computer and use it in GitHub Desktop.
Save JamesSkemp/5a481d8c46dc4e7df3a7 to your computer and use it in GitHub Desktop.

Table altering, in T-SQL

Change table schema

Change the schema on an existing table.

ALTER SCHEMA projectManagement
TRANSFER dbo.RequestPriority

Change column

Alter a column in an existing table.

ALTER TABLE [projectManagement].[Task]
ALTER COLUMN Name varchar(250) not null

Add identity and primary key

Add a new identity column to an existing table.

-- See http://stackoverflow.com/a/3698824/11912
ALTER TABLE JobSupplies add Id INT IDENTITY
ALTER TABLE JobSupplies add constraint PK_JobSupplies primary KEY(Id)
@JamesSkemp
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment