YouTube2Text

Curso SqlServer #2 Credenciales (Login) y Usuarios (Permiso a base de datos) — Transcript

by Multiverso TI · 2,755 words · 391 segments · language en · Watch on YouTube

Full transcript

  1. 0:01Welcome to a new video. We are in the
  2. 0:03SQL Server course. This is our second
  3. 0:06lesson. In this lesson, we will learn a
  4. 0:10bit more about creating users, creating
  5. 0:14logins, and also assigning roles and
  6. 0:17profiles. In the previous lesson, we
  7. 0:22had already created a login, right?
  8. 0:26Access to the system. Here it is. We
  9. 0:31had created the system access with the
  10. 0:34name Williams. Now we are going to go a
  11. 0:37little bit deeper. So, I am already
  12. 0:40logged into SQL Server. System accesses
  13. 0:46, or logins, are found within the
  14. 0:49security folder, inside the logins
  15. 0:52folder. All the system accesses are
  16. 0:56located here, right? All the logins. I
  17. 1:00am making a distinction between logins
  18. 1:04and users because in SQL Server, logins
  19. 1:07are not the same as users. So, what we
  20. 1:11see here in the login folder are the
  21. 1:15credentials to access the server, right
  22. 1:19? They are the credentials to access
  23. 1:21SQL Server. They are users for the
  24. 1:26entire database in general, but then
  25. 1:29there are other users that SQL Server
  26. 1:33creates to assign to a specific
  27. 1:36database so that they cannot have
  28. 1:40access to other databases and other
  29. 1:44schemas, right? So, we are going to
  30. 1:48learn both ways right now. First, we
  31. 1:50will learn how to create logins from
  32. 1:53the login folder. This is very easy,
  33. 1:56right? Just by right-clicking, New
  34. 1:59Login. Here the system will ask us for
  35. 2:03the login name. The login is the
  36. 2:06credential that we will use to access,
  37. 2:09right, with Management Studio. So,
  38. 2:11let's put a name here, for example.
  39. 2:13Let's use Carlos, for example. And when
  40. 2:18creating the login, we can decide
  41. 2:20whether to create it with Windows
  42. 2:22Authentication, that is, without a
  43. 2:24password, or with SQL Server
  44. 2:26Authentication. So, I will use it this
  45. 2:30time. I recommend that you set a
  46. 2:31password. Let's put a simple one, for
  47. 2:33example, 1 2 3 4. And if we click okay,
  48. 2:39the user will be created automatically,
  49. 2:41but it will be created with certain
  50. 2:43restrictions, right? For example, it
  51. 2:46won't have access to tables or access
  52. 2:48to the databases because it doesn't
  53. 2:50have the credentials. To assign the
  54. 2:54credentials, we can go here to where it
  55. 2:57says server roles and here we must
  56. 2:59assign a role. Usually, so that we
  57. 3:04don't have any issues accessing all the
  58. 3:06databases, right? We assign it the
  59. 3:09sysadmin role. It is the same role that
  60. 3:13SQL Server assigns to the SA user,
  61. 3:16which is the user created during the
  62. 3:18database installation. This way, this
  63. 3:22user could access the entire database
  64. 3:25and all objects in the database, right?
  65. 3:30Another thing to keep in mind when
  66. 3:33creating the login is whether we want
  67. 3:36their password to expire or have
  68. 3:38certain characteristics, complying with
  69. 3:41a specific SQL Server policy. I
  70. 3:45recommend that you remove all of that
  71. 3:47so you don't run into problems, because
  72. 3:50all this user management is handled
  73. 3:52from the front-end side with a
  74. 3:54programming language like Visual Basic,
  75. 3:57C#, or Java. So, we don't do this with
  76. 4:00the database connection user, so I
  77. 4:02recommend you remove all this password
  78. 4:05expiration stuff. So, we click here
  79. 4:08where it says "enforce password policy,
  80. 4:12" right? We are telling it not to
  81. 4:16enforce password policies for this
  82. 4:19login. So, I click okay. And look here
  83. 4:23on the left inside my login folder, my
  84. 4:25new login has already been created. Uh,
  85. 4:28Carlos, right? Carlos. The other way to
  86. 4:31create it, I could already log in with
  87. 4:33this user. The other way to create it
  88. 4:35is through code. It could be, for
  89. 4:38example, here "create login" followed
  90. 4:41by the name. of the login. In this case
  91. 4:45, for example, I'm going to create a
  92. 4:47female one, let's say, for example, "
  93. 4:51create login." And to assign the
  94. 4:54password, I say "password" and here I
  95. 5:00put the password. Likewise, for example
  96. 5:02, I will also put 1 2 3 4. Done. With
  97. 5:08this line of code, I would already be
  98. 5:11creating a new login with the password
  99. 5:141 2 3 4. Just like I just created the
  100. 5:17Carlos login from the explorer window,
  101. 5:20right? Now, if I want to set the
  102. 5:23password here, it would be with a comma
  103. 5:26here. I want to remove the password
  104. 5:30expiration, I mean. So, it would be
  105. 5:32here "check." If you notice, I'm going
  106. 5:39to open Carlos here. When I remove the
  107. 5:42password policy, it also automatically
  108. 5:48removed the password expiration. So
  109. 5:52what I have to remove is the password
  110. 5:54policy, so it would be "check." policy
  111. 5:58and I say equals off. With this, my
  112. 6:05password would no longer expire for
  113. 6:07this new login, uh, Judit. I select all
  114. 6:11this and execute it. If I now refresh
  115. 6:15my login folder, notice that my new
  116. 6:18login Judit appears here. Now the only
  117. 6:21thing we would be missing, if I
  118. 6:23double-click here on the login Judit,
  119. 6:26you will notice it doesn't have the
  120. 6:28administrator role, right? So we can do
  121. 6:31that with an additional line of code.
  122. 6:35Now, this is actually very simple. If
  123. 6:38you don't remember that line of code,
  124. 6:40it isn't done when creating the login,
  125. 6:42but rather afterward by altering the
  126. 6:44login. So, I'll leave you here a way to
  127. 6:48know that line of code, right? For
  128. 6:50example, the user, the user Carlos that
  129. 6:52we just created does have it. So, if I
  130. 6:55double-click on the user Carlos, notice
  131. 6:57that this one does have the sysadmin
  132. 7:00role. How can I find out that line of
  133. 7:02code to assign the sysadmin role? Very
  134. 7:05easy. I right-click on the Carlos login
  135. 7:09and I tell it, for example, here "
  136. 7:12script login as" and I select the
  137. 7:14option that says "create" so it shows
  138. 7:17me what code was used to create, to
  139. 7:20assign the admin role to the user.
  140. 7:23Carlos, notice that here is the line of
  141. 7:25code that was used. I can copy this.
  142. 7:28Now I close this. I'm not interested in
  143. 7:30this anymore. And now I am simply
  144. 7:33altering the sysadmin role and I am
  145. 7:35assigning it the login that will also
  146. 7:38have the sysadmin role. In this case,
  147. 7:41the login will be the one I just
  148. 7:42created, which is Judit. Done. So, the
  149. 7:46statement is alter server role sysadmin
  150. 7:51add member and the name of the login to
  151. 7:54which I want to assign the
  152. 7:57administrator role. I select all this,
  153. 8:01execute, and now if I refresh my login
  154. 8:03folder here, if I view my login Judit,
  155. 8:06notice that now it has the sysadmin
  156. 8:09role. So, in this way, we have just
  157. 8:13created with code the same thing we
  158. 8:16created for the user through the Object
  159. 8:19Explorer. So, I'm going to put some
  160. 8:22comments here because I'm going to put
  161. 8:23this in the video description. This is
  162. 8:26login creation and this is role
  163. 8:34assignment to the login. Okay. And now
  164. 8:39there is one more statement here in in
  165. 8:43SQL Server which is user creation.
  166. 8:47There is a statement to create a user,
  167. 8:49it is the create user. Next, we have to
  168. 8:54indicate the name of the user. So, for
  169. 8:58example, I am going to create the user
  170. 9:00Alberto, and we have to indicate to the
  171. 9:03user, uh, what credential they will use
  172. 9:06to access the system, right? You don't
  173. 9:10enter a password for the user; you
  174. 9:12enter a login that was previously
  175. 9:15created, and this login is the one that
  176. 9:18has the user and the password, right?
  177. 9:21So it can be one of those we have
  178. 9:22already created. For example, we have
  179. 9:24created Carlos, we have created Judit,
  180. 9:26and it could be one of these two. We
  181. 9:28cannot assign a password directly to
  182. 9:30the user. Therefore, the user uses a
  183. 9:33created login. So, let's create a new
  184. 9:37login here quickly, also called Alberto
  185. 9:41, right? Down here, I'm going to tell
  186. 9:45it: create a login called Alberto, let
  187. 9:47its password be 1 2 3 4, and let its...
  188. 9:52let its password not expire. I execute.
  189. 9:55Done. If I refresh my logins folder,
  190. 9:58there is my login, Alberto. Now I am
  191. 10:01going to create my user Alberto, who
  192. 10:03will use the Alberto login. I select
  193. 10:06this line of code and execute it.
  194. 10:11That's it. I could have given it
  195. 10:15another name, but, uh, I want to make a
  196. 10:17distinction. A login is one thing, and
  197. 10:19a user is another. The login is the set
  198. 10:23of credentials to access. the system,
  199. 10:27the entire SQL Server environment, and
  200. 10:29they are stored inside this, uh, login
  201. 10:31folder. Users are not assigned, they
  202. 10:35are not stored inside the login folder.
  203. 10:38Users are assigned directly to a
  204. 10:41specific database. In this case, since
  205. 10:44I am, uh, selected on the master
  206. 10:47database, this user login has been
  207. 10:49assigned to the master database. If I
  208. 10:53open the databases here and go to my
  209. 10:55master database, the master database
  210. 10:57has a series of folders and also a
  211. 10:59security folder. If I open the security
  212. 11:02folder, here is my little users folder,
  213. 11:05right? And if I update this folder,
  214. 11:07here is my user Alberto, which could
  215. 11:09have been another name; the user does
  216. 11:11not necessarily have to be the same as
  217. 11:14the login. I could have used, as I say,
  218. 11:16the login for Judit, Carlos, or another
  219. 11:18. So, users are assigned to databases,
  220. 11:22and by doing this, what am I doing? I
  221. 11:25am granting access or permissions so
  222. 11:28that this user has access only to the,
  223. 11:31uh, master database. Even if I, if I
  224. 11:35generate a new SQL Server instance, I
  225. 11:37go here and I am going to log in with,
  226. 11:39with, with the Alberto login. Let's see
  227. 11:42what is going to happen. I'll go here
  228. 11:44and enter Alberto 1 2 3 4. It logs in
  229. 11:49without any problem. But if I want to
  230. 11:51open a database that is not master, for
  231. 11:53example, this one that says "my point
  232. 11:55of sale," I will get an error,
  233. 11:57obviously telling me that I don't have
  234. 11:59permissions, I cannot access those
  235. 12:01databases. Why? Because when I created
  236. 12:04him, I created him as a user who only
  237. 12:07has permission for the master database,
  238. 12:09right? If I wanted this user to have
  239. 12:13access to a database, this one for
  240. 12:16example, "my point of sale," I could,
  241. 12:19for example, disconnect this here and
  242. 12:21create another user. I am going to
  243. 12:25create a user here, for example. Oh no,
  244. 12:30the same user. I'm going to use another
  245. 12:32name. User, for example, Mario. Use
  246. 12:35Alberto's credentials, but have access
  247. 12:37to the "my point of sale" database to
  248. 12:40differentiate, right? The user can be a
  249. 12:43different user that uses the same login
  250. 12:46. In this case, I will create another
  251. 12:49user, Mario, who uses Alberto's login,
  252. 12:51but this time this user Mario has
  253. 12:53access to the "my point of sale"
  254. 12:55database. I select it, execute it, and
  255. 12:59it's already created. So, if I go to my
  256. 13:01database, "my point of sale," right?
  257. 13:04Inside security, I have the user Mario
  258. 13:07created. So, if I access again, I log
  259. 13:12in with user Alberto, sorry, login
  260. 13:17Alberto, no, remember, I do not log in
  261. 13:20with user Mario. User Mario is not used
  262. 13:23to access, right? Once again,
  263. 13:25credentials, the logins, are used to
  264. 13:27access. So, I access with the user,
  265. 13:30with the login Alberto. Now, with the
  266. 13:33login Alberto, I have a user we called
  267. 13:37Alberto, who has permissions for the
  268. 13:40master database, and I have another
  269. 13:43user called Mario, who has permission
  270. 13:48to access the "my point of sale"
  271. 13:49database. So, since I already accessed
  272. 13:52with the login Alberto, both users were
  273. 13:55detected quickly. If I open the "my
  274. 13:58point of sale" database, it will let me
  275. 14:00in because it already detected that I
  276. 14:02have a user related to that login,
  277. 14:04which allows me to access this database
  278. 14:06. But if I, for example, want to access
  279. 14:10the database, my company, I get an
  280. 14:12error because I don't have any user
  281. 14:14related to that login that has
  282. 14:16permission to access that database,
  283. 14:19right? So, that's where the difference
  284. 14:21lies. Users in SQL Server are used as
  285. 14:25permissions to access a specific
  286. 14:29database, right? They are, they are,
  287. 14:32they are a kind of role, right? Instead
  288. 14:35of assigning roles for a database,
  289. 14:37users with database permissions were
  290. 14:40created. But logins are simply the
  291. 14:42credentials; they are the usernames and
  292. 14:44passwords used to access the entire SQL
  293. 14:46Server environment. Now, it is true
  294. 14:50that with the same login we can have
  295. 14:53access to all databases without needing
  296. 14:57to create users, but that will only
  297. 15:00happen if we assign our login the
  298. 15:03administrator role. That is the only
  299. 15:06way; if our login does not have the
  300. 15:09administrator role, our login does not
  301. 15:11have access to any database, right?
  302. 15:14Let's do, let's do this experiment,
  303. 15:17right? So, we have created, for example
  304. 15:19, the user, the login Judit, and we
  305. 15:22have assigned her the administrator
  306. 15:24role. So, if I go here to log in with
  307. 15:29the login Judit, right? Password 1 2 3
  308. 15:364, there it is, it was generated down
  309. 15:39here. And since she has the
  310. 15:41administrator role, I can access all
  311. 15:43databases without any problem. But
  312. 15:46let's do one little thing. I'm going to
  313. 15:48disconnect her, I'm going to remove the
  314. 15:50administrator role. I could do it via
  315. 15:53code, but I'm going to do it over here.
  316. 15:58Let's see, let's go here. Here is the
  317. 16:00security folder. Double click, I go to
  318. 16:03my roles and I tell her, "No, you are
  319. 16:04not going to be an administrator." I
  320. 16:07remove it. Now, since she is not an
  321. 16:10administrator and I haven't created any
  322. 16:14user assigned to a specific database
  323. 16:18for this login, if I log back in with
  324. 16:24this credential, with this login, I
  325. 16:26will no longer be able to access any
  326. 16:29database because she is no longer an
  327. 16:32administrator and she doesn't have any
  328. 16:35user either. So, if I try to open my
  329. 16:37point of sale, or error, I could before
  330. 16:40, my company no, I can no longer. Why?
  331. 16:43Because she doesn't have the
  332. 16:45administrator role and has no user
  333. 16:47created. So there you are more or less
  334. 16:50seeing the differences between a user
  335. 16:53and a login. Now, to delete a users and
  336. 17:00a login; if we want to delete a login,
  337. 17:04and this login has users assigned to it
  338. 17:07, we first have to delete the users.
  339. 17:11For example, if I want to delete the
  340. 17:13Alberto login, we don't have an Alberto
  341. 17:15login, but we have two users created
  342. 17:18for this login. We created the user
  343. 17:21Mario, who has access to the "mi punto
  344. 17:23de venta" database, and before that, we
  345. 17:25created the user with the same name,
  346. 17:27Alberto, who has access to the master
  347. 17:28database. "mi punto de venta" is here,
  348. 17:32it has the user Mario, and the master
  349. 17:35database has the user Alberto here.
  350. 17:37Look, Master has the user Alberto. The
  351. 17:42"mi punto de venta" database has the
  352. 17:43user Mario. And both use the Alberto
  353. 17:46login. I could not delete the Alberto
  354. 17:48login. If I right-click on the Alberto
  355. 17:51login and select delete, an error will
  356. 17:53pop up saying, "You cannot delete it
  357. 17:55because there are users using this uh
  358. 17:57login." So I say, "Okay, then what I
  359. 18:01have to do now is delete the users
  360. 18:04first." I go to my master database,
  361. 18:06Alberto. I delete the users. I mean, no
  362. 18:09, before deleting the login, I delete
  363. 18:11the users. Done, the user was deleted.
  364. 18:15I go to my database, "mi punto de venta
  365. 18:17". I delete the user Mario. Done,
  366. 18:24that's it. And now, yes. it should let
  367. 18:29me delete the uh, Alberto user. If I
  368. 18:33right-click and delete. I mean, it
  369. 18:36should, because before it gave me that
  370. 18:38error that it gets stuck and well, it
  371. 18:40tells me there are still users using
  372. 18:41this login. Actually, we already
  373. 18:44deleted them, and it's because it gets
  374. 18:46stuck, right? I don't know if it's my
  375. 18:50SQL server or my installed instance; I
  376. 18:52can't identify it, but to fix it
  377. 18:54quickly, what I do is disconnect and
  378. 18:57reconnect so that it refreshes, you
  379. 18:59know? that the users have been deleted.
  380. 19:05There. Done, it was deleted. Well, now
  381. 19:24it really was deleted. As I said, it
  382. 19:26kind of gets stuck, right? I don't know
  383. 19:29if it's my database or if that's just
  384. 19:32how it's happening, but it seems to
  385. 19:35take time to update. So, it already
  386. 19:37detected that there are no users
  387. 19:39created and now it allowed me to delete
  388. 19:40the login. Right, so we'll leave it
  389. 19:43there. In the following lessons, we
  390. 19:47will learn a little more about users
  391. 19:49and logins.

About this transcript

This page contains the full transcript of Curso SqlServer #2 Credenciales (Login) y Usuarios (Permiso a base de datos) by Multiverso TI, generated from the public captions YouTube serves with the video. The transcript has 2,755 words across 391 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.