Common SQL change and query statements
Select *, (case when type = 1 then
(Select typename from tableatype where type = 1)
When type = 2 then
(Select typename from tableatype where type = 2)
When type = 3 then
(Select typename from tableatype where type = 3)
Else
(Select typename from tableatype where type = 4)
End
) As typetmp from tablea
======================================
Select *, (select typename from tabletype where type = T. Type) as type1
From tablea t
========================================
-- Modify the table to add a primary key
Alter table [tablea] With nocheck add
Primary Key clustered
(
[ID]
) On [primary]
Go
-- Modify the table to add default values and unique constraints
Alter table [tablea] With nocheck add
Constraint [DF _ tableb _ typen _ 6379339d] default ('') for [typename],
Constraint [DF _ tableb _ typer _ 643a57d6] default ('') for [typeremark],
Constraint [uq _ tablea _ type] unique nonclustered
(
[Type]
) On [primary]
Go
-- Modify the type field of the table to add a foreign key constraint to another table.
Alter table [tablec] add
Constraint [fk_tablec_tablea] foreign key
(
[Type]
) References [tablea] (
[Type]
)
Go