Introduction
00:00:00The video introduces the continuation of learning about SQL Server, presented by Preim Technologies. It sets the stage for exploring advanced concepts and practical applications in database management.
Creating a database
00:00:10Creating and Managing Databases in SQL Server Databases can be created graphically using SQL Server Management Studio or through queries. Graphical creation involves right-clicking the 'databases' folder, selecting 'new database,' naming it, and clicking OK. Alternatively, a query like "CREATE DATABASE [name]" achieves the same result. Each database generates two files: an MDF (Master Data File) containing actual data and an LDF (Log Data File) for transaction logs used during recovery.
Renaming Databases Using Queries or GUI To rename databases in SQL Server, you can use either graphical methods via Management Studio by right-clicking on the database name to select ‘rename’ or execute specific queries such as ALTER DATABASE with MODIFY NAME clause. Another method is employing system-stored procedures like sp_renamedb which requires specifying both old and new names of the target database.
Dropping a database
00:08:15Deleting a Database and Its Files To delete a database, you can use SQL Server Management Studio or execute the DROP DATABASE command. Deleting removes both MDF (data) and LDF (log) files associated with the database. However, if any user is connected to it or running queries, deletion will fail due to its "in-use" status.
Handling In-Use Databases for Deletion When users are connected to a database in multi-user mode, switch it to single-user mode using ALTER DATABASE SET SINGLE_USER WITH ROLLBACK IMMEDIATE. This forces disconnection of all active connections by rolling back incomplete transactions immediately before allowing deletion. Note that system databases like 'master' cannot be deleted under any circumstances.