Managing the Intrinsic Database for LightSwitch
If your LightSwitch application includes a database project in Visual Studio 2013, you can write scripts to manage the intrinsic database whenever you build or deploy that application. For example, you can populate a table with data or add an index for a non-unique field. When you design a LightSwitch application, you can perform some tasks, such as creating tables and editing data, by using the data designer, but other tasks can only be accomplished by adding SQL Server database project and writing a script. For more information about database-management tasks, see SQL Server Data Tools (SSDT).
You create scripts by using the Transact-SQL language, which is the standard for SQL Server development. See Transact-SQL Reference.
When you add a database project to your LightSwitch solution, the contents of that project are incorporated into the intrinsic database that LightSwitch deploys when you build or deploy your application. But you must first associate the database project with the application by opening the Application Designer and then setting the SQL Server Database property. See How to: Add a Database Project to a LightSwitch Application.
You can add multiple database projects to a solution, but you can associate only one project at a time with the LightSwitch application. For example, you can write a different build script in a different database project for each environment to which you expect to deploy the application. You could then associate the appropriate project with the solution before each build.
If you create a post-deployment script, you can populate data, change a schema, or add an index after you deploy your application. See Walkthrough: Managing Data in a LightSwitch Application.
Because the script runs every time that you deploy the application, you must ensure that the script doesn't change the database in ways that you don't intend. For example, you can populate a table with data by using an INSERT statement, but you'll probably end up with multiple copies of the same data. Instead, you should avoid duplication by using a MERGE statement. See Inserting, Updating, and Deleting Data by Using MERGE.