SQL Server What is the use of mdf and ldf in sql?

ubby3x7f  于 2023-06-04  发布在  其他
关注(0)|答案(3)|浏览(288)

I am very new to databases. My friend has shared the following files

  • company_db.sql
  • company.mdf
  • company.ldf

Now I executed the sql file & on successful execution of the command, all the tables, relations are installed on my local machine.

Now definition wise I know what are the .mdf and .ldf files, but I am confused that

  • What is the use of .mdf and .ldf files in my scenario?
  • What should I do with these files?
nue99wik

nue99wik1#

What is the use of mdf and ldf in sql?

Nothing. SQL - the language - has no use of those. SQL Server - the product has, and they are file extensions.

Now definition wise what is mdf and ldf file,

The documentation - which at one point is osmething you may consider reading before asking pointy questions - will tell you that are data and log files.

What is the use of mdf and ldf files?

Let me clarify that - what do you think a database does? Hint: it stored data. For that it needs some place to store bit, which is why all databases interact somehow with storage. SQL Server uses normal files for that (some others use special partitions without a computer visible file system).

MDF (and NDF) store the data, LDF store changes. Why this is needed is a little on the "learn what a database is" layer and has to do with disaster and performance scenarios.

7vux5j2d

7vux5j2d2#

MDF stands for "Master Database File". While you are creating any database that time two extension will create automatically.

The .MDF contains all the main information about the database that are part of SQL Server. Between .MDF file you will get table, function, stored procedure, views and etc.

LDF stands for "Log Database File". The .LDF stores changes related to inserts, deletion, updates, addition, etc. Transaction logs kept in the server help in identifying activities related to unauthorized changes as well as where an error is originating. Log information can sometimes come handy in fixing errors, recovering important data, and identifying anomalies.

mefy6pfw

mefy6pfw3#

.sql file is an extension that is know to sql server, so you can execute that script with right permissions to perform DML operations as user after logging to database.

.MDF is primary files that gets created when you first create an database which stores the data inside the file. .NDF is also another file you can create after creation of DB and you can classifying under one group, you can explicitly route your data to those .NDF datafile's instead of .MDF

.LDF is called as logfile, the LDF is the transaction log. It keeps a record of everything done to the database for rollback purposes.

Hope this helps

相关问题