Drop or Remove Database

Microsoft SQL Server 2017 for Everyone Manipulating Tables and Data
4 minutes
Share the link to this page
You need to have access to the item to view this lesson.
One-time Fee
List Price:  $99.99
You save:  $30
List Price:  €91.90
You save:  €27.57
List Price:  £78.70
You save:  £23.61
List Price:  CA$136.14
You save:  CA$40.84
List Price:  A$149.21
You save:  A$44.76
List Price:  S$134.58
You save:  S$40.38
List Price:  HK$780.18
You save:  HK$234.07
CHF 63.62
List Price:  CHF 90.89
You save:  CHF 27.27
NOK kr751.73
List Price:  NOK kr1,073.95
You save:  NOK kr322.21
DKK kr480.45
List Price:  DKK kr686.39
You save:  DKK kr205.93
List Price:  NZ$162.99
You save:  NZ$48.90
List Price:  د.إ367.26
You save:  د.إ110.19
List Price:  ৳11,707.96
You save:  ৳3,512.74
List Price:  ₹8,329.22
You save:  ₹2,499.01
List Price:  RM468.70
You save:  RM140.62
List Price:  ₦146,985.30
You save:  ₦44,100
List Price:  ₨27,706.17
You save:  ₨8,312.68
List Price:  ฿3,624.43
You save:  ฿1,087.43
List Price:  ₺3,224.01
You save:  ₺967.30
List Price:  B$510.40
You save:  B$153.13
List Price:  R1,807.25
You save:  R542.23
List Price:  Лв179.86
You save:  Лв53.96
List Price:  ₩135,425.45
You save:  ₩40,631.70
List Price:  ₪370.41
You save:  ₪111.13
List Price:  ₱5,770.97
You save:  ₱1,731.46
List Price:  ¥15,565.94
You save:  ¥4,670.25
List Price:  MX$1,660.69
You save:  MX$498.25
List Price:  QR362.75
You save:  QR108.83
List Price:  P1,354.73
You save:  P406.46
List Price:  KSh13,098.69
You save:  KSh3,930
List Price:  E£4,690.53
You save:  E£1,407.30
List Price:  ብር5,727.42
You save:  ብር1,718.40
List Price:  Kz84,733.22
You save:  Kz25,422.51
List Price:  CLP$89,440.82
You save:  CLP$26,834.93
List Price:  CN¥722.24
You save:  CN¥216.69
List Price:  RD$5,826.59
You save:  RD$1,748.15
List Price:  DA13,436.03
You save:  DA4,031.21
List Price:  FJ$222.79
You save:  FJ$66.84
List Price:  Q776.81
You save:  Q233.06
List Price:  GY$20,917.88
You save:  GY$6,275.99
ISK kr9,678.91
List Price:  ISK kr13,827.61
You save:  ISK kr4,148.70
List Price:  DH990.33
You save:  DH297.13
List Price:  L1,760
You save:  L528.05
List Price:  ден5,654.52
You save:  ден1,696.52
List Price:  MOP$803.51
You save:  MOP$241.07
List Price:  N$1,819.78
You save:  N$545.99
List Price:  C$3,674.63
You save:  C$1,102.50
List Price:  रु13,329.38
You save:  रु3,999.21
List Price:  S/371.45
You save:  S/111.44
List Price:  K388.01
You save:  K116.41
List Price:  SAR374.96
You save:  SAR112.50
List Price:  ZK2,538.86
You save:  ZK761.73
List Price:  L457.57
You save:  L137.28
List Price:  Kč2,271.57
You save:  Kč681.54
List Price:  Ft35,609.88
You save:  Ft10,684.03
SEK kr750.08
List Price:  SEK kr1,071.59
You save:  SEK kr321.50
List Price:  ARS$88,666.13
You save:  ARS$26,602.50
List Price:  Bs690.83
You save:  Bs207.27
List Price:  COP$380,678.73
You save:  COP$114,215.04
List Price:  ₡51,169.76
You save:  ₡15,352.46
List Price:  L2,462.78
You save:  L738.91
List Price:  ₲749,130.70
You save:  ₲224,761.68
List Price:  $U3,853.49
You save:  $U1,156.16
List Price:  zł392.01
You save:  zł117.61
Already have an account? Log In


All right, so picking up where we left off, we have two databases successfully created, but read into the at least right now I only need one. So I want to remove one of these databases. So there is a command in SQL. So just remove this line, or I just come in to talk. So you can just use a double dash, right and then what this does is render this line useless. So if you're used to other languages, like maybe C sharp JavaScript, you know you have that double slash, or you have that slash and each language has its own way.

So in SQL, we actually just use a double dash. All right, I want you to see that line turning green. If you are using the default coloring scheme, then you will know that this line is not going to have any bearing on anything once you click Execute. So we can go to the next line, and we will want to delete or in this case, drop it in SQL nomenclature, drop or database, no, I want to warn you be very, very careful and deliberate when you are going to run this and execute this command. Because dropping a database is an irreversible, there's no Recycle Bin, there is no recovering method, or there are a few books at this stage. We're not ready for those.

So be very, very careful and very, very deliberate in writing and further executing this command, so we're going to say a drop database. And then as you go along, you start seeing that there's a pattern and I notice I'm not writing it in all caps. Once again, it is not case sensitive. So drop database, and then we have to specify the database name. So we want to drop school underscore test. So I'll just school underscore test and we see here that the editor is actually kind of picking up on the Once you may want to do, so it's kind of completing what it is that it thinks you want to do based on the information it has available to you.

So it makes it pretty easy to write complex statements in a very short while. So we want to drop the database called school underscore test. And then I'm going to execute that, once again, be very deliberate and careful when doing this, because SQL will not ask you if you're sure you want to delete this item. All right, SQL is just going to see that sorry, SQL Management Studio is just going to say this is the command I got I'm going to execute it. So when I click Execute, there we go. But we still see the database listed here.

So as usual, we just click here and refresh and then we see that there is no longer any trace of school underscore test. And if I attempt to execute this again, then I will get an arrow seen that I cannot drop it because it does not exist or you don't have friends. permission. We know we have permission, we know we just did it. So we know that it's because it does not exist in the same way. And a quick way to comment in SQL Management Studio is to press the Ctrl key and see, as a matter of fact, in the class notes, I have a bunch of keyboard shortcuts that can help you get along quickly and move along in the editor with with minimal effort.

All right, I love keyboard shortcuts. So we can say create database and I will try to create school. Well, we know we already have school so I just want to show you the type of error that you would see. And then it says database school already exists. Please choose a different name so we can't have two databases with the same name. If you need two identical named ones, you know you can use your underscore or you can add a number numbers are acceptable.

Of course the character sets there are strict rules are owned at budds We have infinitely many characters at our disposal. So we can always mix and match and be unique. Alright, so that was how we go about removing a database. Next we look at how we go about creating what we call tables in our database.

Sign Up


Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.