This article is a mirror article of machine translation, please click here to jump to the original article.

View: 16629|Reply: 8

[Source] Database Basics

[Copy link]
Posted on 2/22/2019 3:41:41 PM | | | |
This post was last edited by Kongcida on 2019-2-25 09:05

It really smells

I first wanted to enter the programmer pit when I came into contact with a foreign game in my junior year   The hyperlink login is visible.  (I swear that I don't want to advertise NetEase's so-and-so game, and now it should be copyrighted by NetEase??) )。 When I played this game before, there was no server in China. The game loads super slowly, and a handful of CodeCombat enthusiasts appear. There are a few big cows who set up one in their own hometown, and then they may be busy with their studies and work, and they don't play this game anymore.
At that time, Python had just come out and was hot, so the language I chose in the game was Python.  With each level, I found a little interest and a sense of accomplishment in games and programming. Later, I started watching Python learning videos on MOOC.com.
But, in the end I became a C# development rookie 233333~ .  Later, due to physical reasons, the C#.  I have to say that Microsoft Barbie's IDE is really good, debugging, smart hints emmmmm is really fragrant.....   

Here are some SQL notes from my self-study:

environment

> Windows


Tools needed


> MSSQL: You can go to the official website of Microsoft to download it, or you can go thereThe hyperlink login is visible.Select SQL Server 2017

Text

#Create a database

The above execution results are:



In this way we have created a database, although we have a simpler way to write it as follows:

The result of this writing method is the same as above, and we can also create a database called DemoDb with the default size of the database.

# Delete the database  

We always encounter "Unable to delete the database "DemoDb"", because the database is currently in use." This is because the process connecting to the database has not been closed  

* At this time, we can directly right-click on the database -> close the existing connection to the database -> OK

As shown in the figure:




* Or we can use the method of killing the process with the cursor and then deleting the database


The above is to create a database and delete a database

Step on the pit

When creating the database, you can see Note 1 and Note 2 in the code. Some people will be curious, since Note 1 is the name of the database to be created, why is there a name in Note 2. The note says "The name here refers to the logical name of the database in sys.database_files", so what does this mean? In what scenarios would this name be used?

To find out what's next, listen to the next breakdown......   Ahem, just kidding...

When I first joined the company to do a project, my colleague gave me a .bak database backup. Create a database according to the name above, and then attach the database backup (tutorial later), so that it is backed up to the local area. However, due to project architecture issues, querying a table data will execute n queries for tables associated with the table. In this way, various database operations have caused the database log to soar to 40G in a month (it was really a brain to put the database on the C drive at the beginning, and then the database was moved to another disk). Then I looked for a way to delete the database log in various posts on the Internet, and found a few that all reported errors when executed. I thought it was an online reaching party, but they carried it wrong. Later, I really couldn't do it, so I had to check the reason for the error.



After executing this database code, the error message here is "File 'LogistarOA20171106_log' for database 'LogistarOA20171106' cannot be found in sys.database_files. The file does not exist or has been deleted.The reason for the query is that in "sys.database_files", the logical name of this database is not 'LogistarOA20171106_log'.

The following is the query code:


The query results are:



Obviously the file name and logical name of the database log are different, one is 'LogistarOA20171106_log' and the other is 'CQJHJShippingOA_log'. Let's change Note 5 in the code and it's OK.

emmmmm... Normal people can't step on this pit, and the problems I may encounter are more strange......






Previous:Morning Post | Friday, February 22, 2019
Next:ideaSet up the Alibaba Cloud image in the Maven repository
Posted on 2/23/2019 8:07:58 PM |
This is a quote
Come on!
Posted on 2/23/2019 8:12:13 PM From the phone |
(σ゚∀゚)σ⁶⁶⁶⁶⁶⁶⁶⁶⁶⁶
Posted on 2/23/2019 8:20:58 PM |
I didn't see it yesterday
Posted on 2/23/2019 8:21:56 PM |
Summer Posted on 2019-2-23 20:20
I didn't see it yesterday

Because of the link, the background review was triggered, and it has not been reviewed.
Posted on 2/25/2019 9:13:37 AM |
supported
Posted on 2/25/2019 9:16:36 AM |
6666, support ~ continue to work hard
Posted on 2/25/2019 9:16:42 AM From the phone |
Amazing, young lady, reviewing the database
Posted on 3/5/2019 12:27:17 PM |
Learned!!
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com