Create Table with primary key and Auto Increment && Rename Column && update view model
1.Create a Table: ===========>
create table Slots
(
SlotId int primary key identity(1,1),
Slot Time,
UserId nvarchar(128)
);
2.Rename an Column : ===========>2.Rename an Column : ===========>
EXEC sp_rename 'TableName.OldColumnName', 'NewColumnName', 'COLUMN';
3.Update an View Model : ===========>
CREATE OR ALTER VIEW dbo.Package_Event AS
SELECT
p.PackageId,
e.EventName,
p.CreatedDate,
p.CreatedBy,
uc.UserName AS CreatedByName, -- Name of creator
p.UpdatedDate,
p.UpdatedBy,
uu.UserName AS UpdatedByName, -- Name of updater
p.EventId,
p.PackageName
FROM dbo.Package AS p
INNER JOIN dbo.Events AS e
ON p.EventId = e.EventId
INNER JOIN dbo.UserInfo AS uc
ON p.CreatedBy = uc.UserId
LEFT JOIN dbo.UserInfo AS uu -- LEFT JOIN in case UpdatedBy is NULL
ON p.UpdatedBy = uu.UserId;
4.Check Auto Increment : ===========>
SELECT c.name AS ColumnName,
c.is_identity AS IsIdentity
FROM sys.columns c
INNER JOIN sys.tables t ON c.object_id = t.object_id
WHERE t.name = 'Image'
AND c.name = 'ImageId';
5.Migration===>
dotnet ef migrations add InitialCreate --context Database.Context.CustomerContext
Comments
Post a Comment