Before you begin working with SQL, you'll need to create a database, physical file on which your data is stored. Database file will be flagged with extension .MDF for the data and .LDF for the log file. This 2 files, by default, are created in your SQL installation path, in my case, it's C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA. The simplest way for creating the database with query would be:
Create DatabaseExample if you want to create a database named Test_DB
Create Database Test_DBThis will create a Database named Test_DB with default setting. The physical file will be named Test_DB.MDF and Test_DB.LDF. On further note, you will not be able to copy or delete this 2 files while the SQL server is active or you manually detach this 2 files from the database list. The name of the database must start with underscore (_) or character, no space allowed, and must be consisting of alphanumeric.
While SQL, on default setting, is not case sensitive (means, you can type in create database test_db), it's recommend if you use proper case when naming the database and other SQL objects to make it easier to read.
To delete the database, you can simply use
Drop DatabaseExample:
Drop Database Test_DB
No comments:
Post a Comment