This isn't something I would recommend doing in the table. But rather in a view dependent on the table.
Let the db do what it does well, that being, a standard auto-incrementing integer
as the primary key.
Should you need to ensure uniqueness of the combination, simply add a unique index/key (SQL Server / MySQL).
Below is an example, using SQL Server:
create table Sales (
Id int identity primary key
,BranchCode int
,TRNType varchar(25)
,Year int
,DaysOfYear int
);
create unique index ux_sales_key on Sales (BranchCode, TRNType, Year, DaysOfYear);
go
Note that SQL Server supports computed columns as of 2016. This would also solve your problem, and in the table itself.
And now the same table structure in MySQL
create table Sales (
Id int auto_increment primary key
,BranchCode int
,TRNType varchar(25)
,Year int
,DaysOfYear int
,unique key (BranchCode, TRNType, Year, DaysOfYear)
);
To formulate your "composite key" use a view similar to the following:
create view vSales
as
select
concat(BranchCode, TRNType, Year, DaysOfYear, Id) as SomeCompositeKey
-- the rest of your cols go here
from
Sales;
go