The story of cloning a Microsoft SQL Server database

Recently I was responsible for deploying a Web Application, which leverages SQL Server. For convenience reason, the Backend should automatically realize whether the database structure is expected when it first starts; if not, the database must be programmatically created before the main logic of Backend takes place.