1. How to change col datatype
-- TransDate was in datetime change to date
alter table Transactions
alter column TransDate date
2. How to create primary key on a col
alter table TransactionsArchive
add constraint PK_TransactionsArchive_KeyID primary key clustered (key_ID);
GO
3. How to re-sequence an identity column
alter table List_NotesType
drop constraint PK_List_CommentsType
alter table List_NotesType
drop column NoteType
alter table List_NotesType
add NoteType tinyint identity(1,1)
alter table List_NotesType
add constraint PK_List_NoteTypeID primary key clustered (NoteType);
4. How to change a not null col to null
alter table [Notes]
alter column Comments varchar(500) NULL
5. How to update existing NULL cols with a value
update Notes
set Comments = t.Description
from Notes n join List_NotesType t on n.Type = t.NoteType
where Noteid in (select Noteid from Notes where Comments is null)
No comments:
Post a Comment