Maintaining a database involves shrinking, compacting, and repairing the database. By using SQL Server Management Studio, you can perform all these tasks from within the same dialog box.

To shrink a database

  1. In Management Studio, open Object Explorer.

  2. In Object Explorer, click Connect, and then choose SQL Server Compact 3.5.

  3. In the Connect to Server dialog box, choose the SQL Server Compact 3.5  database that you want to shrink, and then click Connect.

  4. In Object Explorer, right-click the SQL Server Compact 3.5 database that you added and choose Properties.

  5. The Database Properties dialog box opens. Select Shrink and Repair from the left pane.

  6. Click Shrink database by deleting free pages, and then click OK.

To compact a database

  1. In Management Studio, open Object Explorer.

  2. In Object Explorer, click Connect, and then choose SQL Server Compact 3.5.

  3. In the Connect to Server dialog box, choose the SQL Server Compact 3.5 database that you want to compact, and then click Connect.

  4. In Object Explorer, right-click the SQL Server Compact 3.5 database that you added and choose Properties.

  5. The Database Properties dialog box opens. Select Perform full database compaction.

  6. Under File Options, you can either replace the existing database after compacting, or create a new database with a new file name. By selecting the Overwrite Existing Database File check box, you can modify the name and location of the existing database and then replace it.

To repair a database

  1. In Management Studio, open Object Explorer.

  2. In Object Explorer, click Connect, and then choose SQL Server Compact 3.5.

  3. In the Connect to Server dialog box, choose the SQL Server Compact 3.5 database that you want to repair, and then click Connect.

  4. In Object Explorer, right-click the SQL Server Compact 3.5 database that you added and choose Properties.

  5. The Database Properties dialog box opens. Select Repair physically corrupted database.

  6. If you select the Recover corrupted rows check box, you can recover the corrupted rows.

  7. Under File Options, you can either replace the existing database after repairing, or create a new database with a new file name. By selecting the Overwrite Existing Database File check box, you can modify the name and location of the existing database and then replace it.

To create a case-sensitive database

  1. In Management Studio, open Object Explorer.

  2. In Object Explorer, click Connect, and then choose SQL Server Compact 3.5.

  3. In the Connect to Server dialog box, choose <New Database> from the drop-down list.

  4. In the Create New SQL Server Compact Database dialog box, type the name of the database file you wish to create. You may also precede the filename with a file path.

  5. If the case-sensitive database you are creating has the same filename as an existing database, you may check Overwrite existing database file to replace the existing file.

  6. Select the Collation that matches the sorting preferences for your language.

  7. Check the Case sensitive checkbox.

  8. If you want to encrypt your database you must type a password in the New password textbox, and confirm it in the Confirm password text box. If your password does not match the minimum complexity requirements, you will be given an option to change it.

  9. If you chose a password, the encryption mode will change from the default value UNENCRYPTED to Platform Default. You may choose another encryption mode from the Encryption mode drop down list.

  10. Click OK.

Concepts

Using and Maintaining Databases (SQL Server Compact)