Skip to content

C Programming Intermediate Lecture 2 SQL Server CRUD DisplayMemberPath ObservableCollection

FurkanGozukara edited this page Nov 16, 2026 · 1 revision

C# Programming (Intermediate) - Lecture 2: SQL Server, CRUD, DisplayMemberPath, ObservableCollection

C# Programming (Intermediate) - Lecture 2: SQL Server, CRUD, DisplayMemberPath, ObservableCollection

image Hits Patreon BuyMeACoffee Furkan Gözükara Medium Codio Furkan Gözükara Medium

YouTube Channel Furkan Gözükara LinkedIn Udemy Twitter Follow Furkan Gözükara

C# Programming (Advanced/Intermediate) Lectures (2/14) will teach you #CSharp #programming from beginner to intermediate/expert level. This course is an excellent source to learn advanced concepts in C# #coding. If you are a beginner to C#, watch our previous course lectures. The playlist link of the previous course is below.

Full playlist of the previous course: C# For Beginners ⤵️

https://www.youtube.com/playlist?list=PL_pbwdIyffskoSXySh0MdiayPJsBZ7m2o

Discord ➡️ https://bit.ly/SECoursesDiscord

Patreon ➡️ https://www.patreon.com/SECourses

Technology Playlist (30+ Tutorial / Guide / News / Review Videos) ⤵️

https://www.youtube.com/playlist?list=PL_pbwdIyffsnkay6X91BWb9rrfLATUMr3

Stable Diffusion Playlist (30+ Tutorial / Guide Videos) ⤵️

https://www.youtube.com/playlist?list=PL_pbwdIyffsmclLl0O144nQRnezKlNdx3

Please join discord, mention me and ask me any questions. Thank you for like, subscribe, share and Patreon support. I am open to private consulting with Patreon subscription.

Full playlist of this course ⤵️

https://www.youtube.com/playlist?list=PL_pbwdIyffslHaBdS3RUW26RKzSjkl8m4

You can watch for free our C# Programming, ASP .NET Core MVC programming, Machine Learning and Software Engineering related courses on our playlists page ⤵️

https://www.youtube.com/@SECourses/playlists

GitHub code repository of this course (source codes of the lectures) ⤵️

https://github.com/FurkanGozukara/Introduction-to-Programming-2-2021

The topics that have been covered in Lecture 2:

  • How to compose a custom class

  • How to use overwritten property to display the custom formatted results of other properties inside a class

  • How to compose read-only or write-only properties inside a custom class

  • How to do inline If and Else

  • How to use the Switch statement

  • How to use For loop

  • How to use and utilize ObservableCollection to display custom class objects inside a ListBox // this can be applied to any main window objects

  • How to use ItemsSource DisplayMemberPath of a ListBox inside a WPF application

  • How to access elements of ListBox as an instance of a custom class when selection changed

  • How to install Microsoft SQL Server 2019 Developer edition

  • How to install SQL Server Management Studio

  • How to compose database and table with SQL Server Management Studio

  • What is database collation and what difference does it make

  • How to write insert, update, delete, and select queries with SQL Server Management Studio

  • When to write full path or not in SQL queries such as the database.dbo.table or just table

  • How to uniquely identify a record and do SQL operations such as select, update, and delete certain records

  • How to use "in" keyword in SQL queries

Composing a Custom Class:

When it comes to object-oriented programming, one of the essential concepts is the creation of custom classes. Creating a custom class in any programming language allows the developer to define a data structure that fits their specific needs. A class is a blueprint or a template for creating objects. An object is an instance of a class that has its own identity and can have its own set of values for the class's variables.

Read-only or Write-only Properties:

Sometimes, it may be necessary to define properties that can only be read or written to. To accomplish this, you can define read-only or write-only properties in your custom class. A read-only property is a property that can only be accessed for reading. It can be useful when you want to prevent accidental modification of a property's value. On the other hand, a write-only property is a property that can only be accessed for writing.

Inline If and Else:

In programming, sometimes it is necessary to execute a particular block of code based on a condition. One way to accomplish this is by using an If statement. An If statement evaluates a condition and executes a block of code if the condition is true. An inline If statement, also known as a ternary operator, is a shorthand way to write an If statement. It allows you to write a conditional expression in a single line of code.

ObservableCollection:

An ObservableCollection is a collection class in the .NET Framework that provides notifications when items are added, removed, or changed. It is useful when you want to display a collection of objects in a UI element such as a ListBox. The ObservableCollection class implements the INotifyCollectionChanged interface, which defines an event that is raised when the collection is changed.

ItemsSource DisplayMemberPath of a ListBox:

In a WPF application, the ItemsSource and DisplayMemberPath properties of a ListBox can be used to display a collection of objects. The ItemsSource property specifies the collection of objects to display, and the DisplayMemberPath property specifies the property of the object to display. When the ListBox is bound to an ObservableCollection of custom objects, the DisplayMemberPath property can be set to the name of a property of the custom object to display.

Video Transcription

  • 00:00:01 Hello dear students, welcome to the Lecture 2 of Advanced Programming with C-Sharp Courses.

  • 00:00:06 As I have previously explained, it is also known as Introduction to Programming 2. So

  • 00:00:11 today we will start learning about databases with Microsoft SQL Server. To be able to show

  • 00:00:22 you how to install it, I have uninstalled it from my computer so I will reinstall it

  • 00:00:28 from scratch so that you can learn how to download and install it. To do that, let's

  • 00:00:36 search for Microsoft SQL Server and when we open the page, it opens this page, I will

  • 00:00:48 convert it into English with this way. So we will download the developer edition which

  • 00:00:56 is the free edition of Microsoft SQL Server for developers. It is downloaded. Let's open

  • 00:01:09 it. So there are several options. I think it is best to download media and then install

  • 00:01:25 it. So we can choose the media downloading options here. I will just let it as default

  • 00:01:34 because I see they are correct. In addition to the Microsoft SQL Server, we will also

  • 00:01:48 use Microsoft SQL Server Management Studio. You see here, it is at the same page at the

  • 00:01:58 bottom, download SQL Server Management Studio. So let's download it as well and meanwhile

  • 00:02:05 they are downloading, we will continue to do our programming. So I am clicking this.

  • 00:02:12 By the way,: there are several issues. If your Windows is not Windows 10, then if you

  • 00:02:20 download the latest Microsoft SQL Server and SQL Server Management Studio, they may not

  • 00:02:27 work on your computer. So if you have older version of Windows, then you have to download

  • 00:02:34 older version of Microsoft SQL Server and probably SQL Server Management Studio. Also

  • 00:02:43 I suggest you to upgrade your Windows to Windows 10 because of this reason so that you can

  • 00:02:50 use the latest technology, latest software. So they have started downloading. Meanwhile,

  • 00:02:57 let's compose our V2 project and continue to recap what we have seen previous semester

  • 00:03:08 and start learning new things as well. So let's compose the project. So I will pick

  • 00:03:25 WPF app .NET. As you know, this is .NET core and the older framework is named as .NET framework.

  • 00:03:35 And I will pick the repository, the folder, the directory. So Introduction to Program

  • 00:03:44 2 Lectures here and it will be Lecture 2. Our downloads are continuing here. So the

  • 00:04:30 project is getting initialized. Okay the project is ready, so today I would like to recap the

  • 00:05:03 dictionaries and lists for each loops. Okay so let's start with the list box and we will

  • 00:05:16 also add custom class objects to the list box. So first, let's define its dimensions.

  • 00:05:27 Okay one moment. Okay so now we can see it after setting some dimensions. Okay let's

  • 00:05:41 give it a name so we can access it. This name as list box main all right and let's add a

  • 00:05:55 button. Okay, let's code as test and let's compose the click event here. All right? So

  • 00:06:20 I want to add custom objects to my list box and use them when click it or do anything

  • 00:06:33 else we want. So to do that, I will compose a class as let's name it as students okay

  • 00:06:44 or student and it will have some properties. Let's say student number as integer and string

  • 00:06:58 as student name and what else we can use. Okay, how do I compose it quickly I type prop

  • 00:07:16 and then I hit double tap like this, let me show prop, double tap, tap. It all composes

  • 00:07:25 this template and I can name it as something like this. Okay okay now in this list box

  • 00:07:40 I want to show these as values and let's get some names list from internet and I sign them

  • 00:07:54 randomly. Let's say Turkish name list or some names here. Okay let's pick some names from

  • 00:08:27 here as Turkish male names and then add a boolean as let's say female or male. Okay,

  • 00:08:48 I will add text to my project text file. Let's say male names txt here. Okay, I believe these

  • 00:09:15 are separated with okay it is fine we can use them still, but how can we use it? Let's

  • 00:09:39 see the characters representation. I am looking for a better source but here we don't know

  • 00:10:12 the gender. Okay, it is male. Nice. We can use this. It is much better and female here.

  • 00:10:22 Okay, these are some not common names. Therefore don't get confused and let's remove this here.

  • 00:10:37 Okay, we have some male names and I will append female names. Okay here let's call this and

  • 00:11:10 let's see play this as well. Okay, we have some female names and male names and let's

  • 00:11:22 see our download status. Okay, it's downloading all right. What we are going to do is we will

  • 00:11:32 compose a certain number of instances of this student class and then we will get them displayed

  • 00:11:43 on the list box. Okay, so to do that, we will use observable collection. Let's see the format.

  • 00:12:11 Okay, something like this should work. Okay, you see I have to add the reference and I'm

  • 00:12:32 adding it. So this is observable collection and let's name it as students or or or see

  • 00:12:42 students. Okay, so when I click the temp button by the way, I will initialize it when the

  • 00:12:52 application starts so it will be ready to use. I will generate 100 random instances

  • 00:13:00 or let's say 10 instances of students. How am I going to do that? By the way, I have

  • 00:13:05 to change this type of this into this type of observable collection into student, which

  • 00:13:12 is my class custom class. Okay, so we will generate a number and I will make it something

  • 00:13:21 like eight digits. So let's compose our random seed whenever the button is. Click it. Okay,

  • 00:13:33 and let's initialize an instance of students. Let's say okay. It is initialized by with

  • 00:13:50 default values. What were the default values: integers and boolean integer is zero, boolean

  • 00:13:58 is false and strings are null. Okay, so let's assign the student number first so the student

  • 00:14:06 number will be equal to my rounds next and I will make it between 10 million and nine

  • 00:14:22 nine nine. Okay, so it will be something eight digit. However, I have to also keep that no

  • 00:14:38 students gets the same number because you know the students number should be unique.

  • 00:14:45 However, right now I won't care about that. So the student number will be like this and

  • 00:14:52 student name. Okay, to compose student names I will get two random pics from our file files

  • 00:15:06 and merge them. This is not very much sense making, but it is also not that much important

  • 00:15:15 as well. So let's do it. Okay to be able to access these files, they have to be inside

  • 00:15:24 my debug folder to be able to access them directly. So whenever the button is click

  • 00:15:33 it I can load them into a string list. Something like this: mail names equal to file dot. By

  • 00:15:45 the way, the file is not available as you see because I have to add its class rep its

  • 00:15:56 reference from here using system IO read all lines. Okay, this will read it into an array

  • 00:16:08 by default so the name will be mail names txt then to list. Okay, so the to list is

  • 00:16:21 the link queue and this is the method inside file class and right now it's ready. Let's

  • 00:16:32 copy and paste it like this: for female names and female. Okay, so is this enough? I mean

  • 00:16:42 will it work when I run the application right now? no, it will throw an error. Let me show

  • 00:16:48 you that which error it will throw, it will throw unhandled exception as the file not

  • 00:17:06 found you will see okay you see system IO file not found exception. Okay, even though

  • 00:17:16 I have added them to my project, they are not available in the debug folder so I can

  • 00:17:23 link them. Let's see if I can link them like this. No, I am not able to link them like

  • 00:17:33 that. So I will use the proper name. There is build action. Build action means that whenever

  • 00:17:40 you build your application, rebuild or run it and before you run it, it will build it.

  • 00:17:46 That action will happen. So the build action will be as copy if never okay and here none.

  • 00:18:00 Okay, we don't need anything and one more thing we need is

  • 00:18:13 I think we may need to set it as resource but I am not sure. Let's first try as copy

  • 00:18:20 if never and let's run the application and test. Probably we have to set them as resources

  • 00:18:28 in the build action but to be sure I will test it. Oh it is working so it is working.

  • 00:18:39 When we open the debug folder we will see it is they are there inside our debug folder

  • 00:18:48 and whenever I change files they will be copied again. Okay so they are here as you can see

  • 00:18:55 copied into debug folder. Okay let's see our download. Okay, download is done. So let me

  • 00:19:03 show you how to install SQL server I have opened the download folder and I right click

  • 00:19:10 on the ISO and click mount. It may change in your computer. If your language is different

  • 00:19:18 then I right, click the setup and run as administrators. Okay, okay, then we click installation and

  • 00:19:33 we click new SQL server standalone installation this one and then we specify the free edition

  • 00:19:45 is never open. We accept the license. Okay, let's continue writing our code. Meanwhile,

  • 00:20:23 it is working. Oh, it is working. Okay, so now we have the random numbers. Now let's

  • 00:20:32 first we need to decide whether it will be male or female. So let's decide male or female

  • 00:20:40 as something like this. I will use inline if you will see it next and between zero and

  • 00:20:56 one. So you see max value exclusive upper bounds. So it can be either zero or one exclusive

  • 00:21:05 so it doesn't include the max value so it can be zero and one. Currently if the random

  • 00:21:13 number is equal to zero, I will set them as male. Okay, something like this true as false.

  • 00:21:25 Okay, so this is inline if this is equal to, let me show you if equal to zero. Okay, so

  • 00:21:58 you see this is equal to this one. However, you see how cleaner it is to write as this

  • 00:22:06 way and if it is appropriate, you can write your if an assignment like this I use it commonly.

  • 00:22:18 Okay, so let's continue. And then I will use a switch to use switch. You see the code snippet

  • 00:22:28 has appeared after I have typed swe and I double click top and the switch template is

  • 00:22:36 generated as a switch. I will use the boolean male and which values you will have is we

  • 00:22:46 will have case as true. So if it is a male and then we will have case as false not male.

  • 00:22:58 Okay, so if it is male, we will use the male list and let's generate two strings as first

  • 00:23:07 name and the surname. So the first name will be equal to male names or we can even use

  • 00:23:21 a better approach. So let me show you the better approach. Okay so the better approach

  • 00:23:29 is using the reference types of lists. What I mean is I can use something like this user

  • 00:23:38 list equal to main names. So what does this do is simply keeping reference address or

  • 00:23:54 let's say of list of males. Okay so this is this doesn't generate a copy of list of males,

  • 00:24:09 this just references to it. Maybe maybe I will just pass it for now because it may get

  • 00:24:16 you confusing. Yeah, I will use the simpler way. So the simpler way is let's compose them

  • 00:24:28 like this. Okay, so I have generated two strings. They are currently set as null and if it is

  • 00:24:44 male, you see case true. I will assign them like this equal to male names I think I can

  • 00:25:00 sort them. Let's use the random the easier way. Next, it will be between zero and the

  • 00:25:09 number of items inside that list because it is exclusive the upper bound. So something

  • 00:25:18 like this and the surname let's see it will be like this as well. So you see we are using

  • 00:25:33 copy paste code. We could bypass this if we were using the references of lists. However,

  • 00:25:41 it is a bit advanced topic. Therefore I will just pass it for this time so you will not

  • 00:25:52 get confused and this time we will be using the female names. Okay now actually we don't

  • 00:26:01 even need to set this. But okay, let's keep them. We will set the object variable student

  • 00:26:12 name equal to first name plus surname. Okay, okay and finally there will be an email so

  • 00:26:26 we can set the email something like this. Let me show and let's say equal to first name

  • 00:26:41 to lower or we need to trim the special characters accents. Let's find it. Okay so there is regex

  • 00:27:14 option. Yeah I think we can use this. So I will set the email as by the we need to add

  • 00:27:33 an empty character between something like this. Okay student name, replace empty character

  • 00:27:43 with this and for to be able to reference regex I have to add its reference as this

  • 00:27:56 system takes regular expressions. So regular expressions is like a new programmed language.

  • 00:28:07 It's the topic of another lesson or course. Therefore, I won't enter it. However, this

  • 00:28:15 will remove all characters inside the given string other than English letters. Okay, so

  • 00:28:25 this is defining its range. I will just keep it and then I will add like gmail come. Okay.

  • 00:28:35 Once we have composed our student object, then we will add them into our list. Okay,

  • 00:28:48 at random student. Okay, so this will add my random stupid student object into my oc

  • 00:28:59 students or observable collection. There is another key issue. If I define this inside

  • 00:29:08 here. It will break everything. Okay, so I will show you the both cases. However, before

  • 00:29:18 we progress first, let's check how our code is working so far and before even going there.

  • 00:29:29 Let's continue with our microsoft sql installation. Okay, it is passed. So I click next. Okay

  • 00:29:37 here what we need is database engine and others are not necessary. However, let's add analysis

  • 00:29:49 services. We may use it. You see there are some other shared features. So many features

  • 00:29:56 actually like machine learning our python java full text semantic search. Probably we

  • 00:30:04 won't be using them in this course. Connectivity: okay, let's add this one as well. You may

  • 00:30:26 need it. Okay, okay, one moment. Okay, master data services: okay, probably we won't be

  • 00:30:39 needing them. So let's click next. You see they are all default folders, program files.

  • 00:30:49 Microsoft sql server. Okay, one moment. Okay, keeping the default instance name is important

  • 00:30:59 because if you change the instance id, then when you reference something or when you try

  • 00:31:05 to connect, it may cause you some problems. So I am keeping msql server as the instance

  • 00:31:13 name. Okay, okay here. I won't touch anything. Next okay here we will use windows authentication.

  • 00:31:36 However, you can also access it with root password. Something like this, let me show

  • 00:31:43 I am clicking at current user by the way you have. You also need to add the current user

  • 00:31:49 as well. Even if you use windows authentication, you see sql server administrators have unrestricted

  • 00:32:03 access. Okay, it has added. This is my computer name and it is very important when you connect

  • 00:32:10 to your sql server. Instance I will show you that I am also setting a password something

  • 00:32:17 as 1234 1234. Okay and next. Okay here: I don't touch anything but I am also adding

  • 00:32:29 current users to have to add as an administrator. These access restrictions are topic of another

  • 00:32:40 course, so I won't be delving into them. Let's continue. Okay, this is the summary and let's

  • 00:32:50 click install. Okay now it will install the sql server 2019 developer edition at the background

  • 00:32:59 and now let's return to our application. So let's test our application. Until so far how

  • 00:33:07 is it is how it is working and to test it in debug mode? I have put a breakpoint here.

  • 00:33:21 Okay, when I click the test button, let's go step by step. So our random object is composite.

  • 00:33:32 Our lists are composites you see here and here. Then let's continue with our for loop.

  • 00:33:46 So the student object is composed from student class. You see the default values. Mail is

  • 00:33:54 false, student number zero, student email and name are null because they are string

  • 00:34:01 type and first we generate the random number something like this and then we decide male

  • 00:34:09 or female. Okay, it is decided as female because male is false. Okay, then we enter our speech

  • 00:34:18 statement. So let's see our first name. Okay and let's see the second surname. Oh so it

  • 00:34:31 appears that this was exclusive. Oh I see the error. Okay, I will give you 10 seconds

  • 00:34:47 to find the error here and I wonder if we will able to find it or not. Okay, okay, the

  • 00:34:58 error is this. You see the list. The number of elements in the male list is much bigger

  • 00:35:07 than the number of elements in female list. Therefore, when you give as an input to mail

  • 00:35:13 this count, we got an error. Okay, I have fixed it now. I am putting my breakpoint here.

  • 00:35:21 I have removed the previous breakpoint. Okay, so the first name and the surname decided.

  • 00:35:41 You see this time it is male and student name is assigned. Let's see. Okay, you see it has

  • 00:35:50 non-english characters as well and let's convert it into mail email. Okay, it is converted

  • 00:35:58 as email something like this and then it is added to our list. Okay, so it is working

  • 00:36:09 as expected and what else we need. We will set the item source of listbox main as equal

  • 00:36:19 to observable collection and I am setting it here. By the way, even though we are initializing

  • 00:36:28 it here, we can assign it like this because the main window is executed. This is the constructor

  • 00:36:39 of main window class. After these fields and properties are initialized, so if we put breakpoint

  • 00:36:48 in the both place, we can see the order of the application initialization. Okay, you

  • 00:37:02 see this is first initialized it even though it is written under the method then this will

  • 00:37:10 be assigned. Therefore, this is not null. Okay, it is initialized okay at the beginning

  • 00:37:19 there is no objects. When I click test you see they are coming like this. However, it

  • 00:37:25 is showing me as an object because I didn't set its display member. I also need to set

  • 00:37:33 its display member. It is set with display member path as equal to okay. So what I want

  • 00:37:49 to show? Let's see what I want to show as display member. Okay I am thinking what to

  • 00:38:08 display I think we can display student ID plus name so display member path is set as

  • 00:38:25 get and set so let's see how to override it. Oh I think I have a great idea so let me show

  • 00:38:56 you so as a display member set I will use a string and I will set it as display member

  • 00:39:07 name it. However, I will override the get method so the get method will be overridden

  • 00:39:24 like this. Okay, when we set I think we should be able to get and set like this. Return set

  • 00:39:50 is I think I can remove this. Okay, so it won't have a set method. It will have only

  • 00:39:57 get and the get method will return this dot. I think first, I will display the student

  • 00:40:06 number to string and zero and then I will add a top character and then I will add the

  • 00:40:17 student name name. Okay and I think we can also add the email plus email. Okay, so when

  • 00:40:41 I try to access display member of an instance what I will get, you will see in a moment.

  • 00:40:50 Let me show you this is actually a pretty awesome. However, it may throw me an error

  • 00:41:01 that I'm trying to access. Oh yeah, I have to first set it so the path will be equal

  • 00:41:13 to like this. Okay, so let's run the application by the way here. Yeah, it should automatically

  • 00:41:20 handle null values. In this case. I believe okay, okay, so this random student initialize

  • 00:41:30 it when I hover my mouse. Okay, you'll see the display member pet is displayed as zero

  • 00:41:36 and null. Okay, let's set the name okay. Name is set when I hover my mouse. Okay, so the

  • 00:41:48 display member pet is something like this now and after I set the email. Okay, now the

  • 00:41:58 display member pet is something like this. You see how cool it is. This is an awesome

  • 00:42:04 feature and I think we can even customize it even more. Let's customize it as I will

  • 00:42:12 use dollars and inline format ID and top and name name top. Okay. I will also leave an

  • 00:42:38 empty space and email email. Okay, now we can remove this part. Okay, now you get the

  • 00:42:49 idea I am I believe now it should display on the list box. Okay, looks like our SQL

  • 00:42:58 Server installation is done. Okay, okay, now it is working perfectly as we wanted. So okay,

  • 00:43:18 let's make this even bigger. Okay, now let's install the SQL Server development tool I

  • 00:43:33 am closing the installer of SQL okay, developer edition is successfully installed now inside

  • 00:43:41 the downloads. I will run the SQL Server management studio. Okay, let's make it even bigger so

  • 00:44:07 we can see better. It is not very important. Okay, okay I'm just clicking install I'm hoping

  • 00:44:37 that it will install without requiring me to restart. Okay, okay, it is working. So

  • 00:44:55 the 10 values are generating. I did I think we can add some more top characters here so

  • 00:45:07 it will be looking better? Okay, so here we can see them. I think we can also add the

  • 00:45:42 gender as well. So let's add the gender here. I will also write an inline if query inside

  • 00:45:57 here. So okay if it is true then it will be male else. Okay, okay so we have added gender

  • 00:46:20 option as well so let's write it. Okay now we can see when I click again. They will edit

  • 00:46:45 to the end of to this and automatically updated and here you see and here's I can add as many

  • 00:46:54 as I want generate okay so you see this is kind of generating a test data for your project

  • 00:47:04 because sometimes you want to generate some let's say generic test data into your project

  • 00:47:14 so that you can test your methods efficiently. Okay I think we have shown what we wanted.

  • 00:47:25 Let's take notes of what we have seen so far. Okay, we have seen how to compose the custom

  • 00:47:53 class, how to use, how to use overrided written post I don't know overridden okay, this is

  • 00:48:29 hard to understand but this is what we are doing here and we cannot also set the you

  • 00:48:41 see display members something like this so let's try that as well. So you see it is giving

  • 00:48:48 man error because it is read only because we have only get method. If we didn't put

  • 00:49:12 get and we have put on the set it would be right only. Okay okay how to compose, read

  • 00:49:23 only or write only properties inside class okay inline if check if and else I think this

  • 00:49:52 is a correct explanation how to switch these are simple stuff. Okay, how to assign or let's

  • 00:50:16 say utilize observable collection to display custom class objects inside a list. Okay,

  • 00:50:58 any okay I think we have shown everything okay and now I want to show you something

  • 00:51:23 else when we click an element I want to display that click it element values one by one by

  • 00:51:41 one. So how am I going to do that is I think selection change

  • 00:52:06 or selected I think we can. Let's first try the selected

  • 00:52:17 method. So how can we do that list box item perhaps something like this. Actually, we

  • 00:53:14 don't even need this because I already have the reference of this box, main and selected

  • 00:53:22 item. Okay, so let's show message box, show this box main, selected item dot. Okay, now

  • 00:53:37 the selected item is type of student. Therefore, I will convert it to that type with explicit

  • 00:53:49 conversion. Okay. And then I have to put another parentheses and then I can show for example

  • 00:54:02 student numbers and two strings. Okay, and let's format it as well. Let's run the application.

  • 00:54:17 Okay, our SQL Server Management Studio is installed as well. Okay, it is with Azure

  • 00:54:29 Data Studio. Okay, it says we have an error so it says that this box doesn't have. So

  • 00:54:49 let's let's make a selection change not selected and let's remove the previous reference. Since

  • 00:55:09 we are binding a custom class, we can access its each member values. So when I select one

  • 00:55:23 okay, you see I am displaying its ID individually I'm displaying its ID you see how useful it

  • 00:55:32 is like this. Okay and okay so this is important. This is called as I don't know the term but

  • 00:56:14 you get how to. You get the idea. So let's note that as well. How to access. Okay, so

  • 00:56:49 with this approach, you can do so many things. This is pretty advanced and useful programming.

  • 00:57:03 I think now we can start seeing databases all right. So how we are going to use the

  • 00:57:19 database now? we are going to start it now. We have installed Microsoft SQL Server and

  • 00:57:26 SQL when I type SQL then I click apps. It doesn't show. So let's type as management.

  • 00:57:46 Okay here: Microsoft SQL Server Management Studio I am opening it I think we can also

  • 00:57:57 find it here under here. Maybe? not sure. Yeah here. Okay, it is now getting open it.

  • 00:58:21 This is the user graphical user interface to manage SQL Server databases objects. Whatever

  • 00:58:29 you want I click it, connect. So it is connecting the default name instance. So I will show

  • 00:58:36 you again. So from here click it. Okay, so the server type is database engine. There

  • 00:59:02 are other engines but we are going to use database so you see the server name. This

  • 00:59:06 is the name of my computers. You can also find your computer name from I think okay

  • 00:59:17 I after I have opened this page I right click this PC and I click properties and here it

  • 00:59:26 shows my device ID product, ID device name processor, my Windows type and Windows Edition

  • 00:59:36 and whatever. So this is my device name. Actually this is the name that we have installed our

  • 00:59:44 server during installation. Then I am choosing Windows authentication I can also use it SQL

  • 00:59:52 Server authentication and for login I can use as a system administrator and the password

  • 00:59:58 is one two three four. Okay, when I click connect, it will connect also so you can use

  • 01:00:06 both way you can use Windows authentication or you can use the defined authentication

  • 01:00:13 during your installation. Okay, both is possible. So here under databases we can we see the

  • 01:00:21 system database and database synapses. So I will compose our first database as I click

  • 01:00:27 databases right click and I click new database. Okay so the database name will be as school,

  • 01:00:38 the owner will be default and here the path of the database file will be located. The

  • 01:00:48 file name will be automatically decided I won't touch them. There is also auto growth

  • 01:00:54 size, max size, initial size and then there are options here you can see the recovery

  • 01:01:02 model. You should leave it as full pump ability level. Here you see you can define with older

  • 01:01:09 version of SQL servers or with the latest version and containment time I do none. Okay,

  • 01:01:17 collation collation is important because according to your collation, the data you can hold in

  • 01:01:25 your database changes. It also changes your databases behavior when you do a search insert,

  • 01:01:34 update, delete. So you should pick your collation according to your needs. There is Turkish

  • 01:01:45 or English whatever you want any language probably. So the English is defined as I think

  • 01:01:57 Latin here and you see there are some extensions. Each one of them means something else. So

  • 01:02:06 I will show you the Turkish one or this time here. Okay, you see there are so many options,

  • 01:02:18 which one should you choose? So if you want your accent to be sensitive then you have

  • 01:02:25 to pick a s. A s means it is accent sensitive. What does accent sensitive means? Let's say

  • 01:02:32 I will type here so everyone can understand. Okay, let's say your name is Ayshe if you

  • 01:02:44 if you pick it. If you pick your collation as accent sensitive and you search for Ayshe

  • 01:02:55 then you will get no results because it is accent sensitive. If you pick, by the way,

  • 01:03:09 accent sensitive is a s. If you pick AI which means accent insensitive then Ayshe will return

  • 01:03:23 Ayshe as well. So this is about accent sensitive and accent insensitive. Then there is also

  • 01:03:29 case sensitivity if you pick your collation as case sensitive. So the case sensitive is

  • 01:03:41 c s. You see here c s like this. Then if you search for Ayshe in your database you will

  • 01:04:00 not get result. Ayshe okay, however, if you pick your collation as let's say case insensitive

  • 01:04:16 case insensitive c I then Ayshe or Ayshe will return all cases. Okay, so let's save this

  • 01:04:38 as collation explanation. Okay, so this is about collation. There are also some other

  • 01:05:02 options you can look for them on the internet if you need. However, usually you don't need

  • 01:05:07 so we will set our database according to our needs. If you if you want that to be accent

  • 01:05:14 sensitive then we set accent sensitive. If you don't want then we can set as accent insensitive

  • 01:05:21 so I will set it as a case insensitive and accent sensitive. Okay, or we can do as case

  • 01:05:32 insensitive and accent insensitive. As you can see here, this one is case insensitive

  • 01:05:37 and accent insensitive. The language also defines which characters will be available

  • 01:05:45 in your database. So as I said, pick your compose your database as your need. There

  • 01:05:51 are also other options here. Update, statistics, create statistics, and other things. These

  • 01:05:58 are all more advanced features for now. I won't be touching them because we just need

  • 01:06:06 to learn how to access programmatically to our database. Modified. Okay, so our school

  • 01:06:12 database is created composite. Then we will compose tables because the microsoft sql server

  • 01:06:20 is a relational database. Therefore. Uh, it have tables and relations between tables.

  • 01:06:29 Okay, so let's compose our first table. The database design is entirely a different course.

  • 01:06:39 Uh, it is pretty complex and if you don't do it properly then you may have a lot of

  • 01:06:48 performance issues. So know that as well. So let's create compose a table. The first

  • 01:06:56 table will be users. I will be held. I will help these variables inside this user table.

  • 01:07:05 So the column name will be first column name will be student id. I will define it as integers.

  • 01:07:14 Will I alone knows knows means that if you if you have objects that have null uh variable

  • 01:07:23 having um, student student ids then you can select alone rules. By the way, the database

  • 01:07:31 null and c sharp null are different. Okay, so don't get confused. Uh, in c sharp integer

  • 01:07:39 cannot be null. It can be only default zero. Uh. However, in database it may be null database:

  • 01:07:48 no by the way. So I want alone rules then it will have student name. Okay, there are

  • 01:07:57 now uh. Database types and chart and var chart and other things. So let's uh, see them as

  • 01:08:04 well. Database: um column data type list: okay, okay here the data types. So okay, not

  • 01:08:29 this list. Okay character size: so the character is uh, fixed. Okay, let's read them each.

  • 01:08:39 One of them. So the character which one is character character is this one char and then

  • 01:08:44 you define the size like 10, 20, 100? Whatever you want. Let's read the definition. A fixed

  • 01:08:53 length string can contain letters, numbers, and special characters. The size parameter

  • 01:08:59 specifies the column length in characters can be from 0 to 255. Default is 1. Okay,

  • 01:09:08 so the character. If you set characters then it can be between 0 and 205. Then there is

  • 01:09:15 a var character. Uh, which one is var character here? Let me show uh var character here. You

  • 01:09:23 can also set its size maximum size. By the way. A variable length string can contain

  • 01:09:31 letters, numbers, and special characters. The size parameter specifies the maximum column

  • 01:09:37 length in characters can be from 0 to 65535. Okay, then there is binary. It is equal to

  • 01:09:46 character, but stores only binary byte strings. The size parameter specifies column length

  • 01:09:51 in bytes. Default is one I have. Uh, by the way, why do we use binary? If you wonder?

  • 01:09:59 uh, I think I have never used binary until now. Okay, then there is var binary. Uh, let's

  • 01:10:17 use binary and var binary as well. Equal to char, but stores binary byte strings. The

  • 01:10:24 size parameter specifies the column length in bytes. Default is one okay, and then var

  • 01:10:32 binary equal to varchar, but stores binary byte strings. The size parameter specifies

  • 01:10:39 the maximum column length in bytes. Then tiny blob. Okay, it is about binary light large

  • 01:10:48 objects that I have never used it as well. There is tiny text text size. Okay, these

  • 01:10:54 are by the way, not sql. Yes, this is my sql. Let's look for microsoft sql. Yeah, I think

  • 01:11:03 this is microsoft sql. Okay, now uh, this is more appropriate. Okay character and uh,

  • 01:11:11 we fix it with character. It can be maximum 8 000 characters. Then var character and variable

  • 01:11:19 with characters thing like this then var character max. Okay, if you want unlimited uh variable

  • 01:11:29 holding, then it is this one var character max. You see it. It can hold up to one billion

  • 01:11:38 characters. Then there is text you see. It can even hold up to uh two gigabytes of text

  • 01:11:47 data. By the way, this is the storage they are taking. If you define var character, it

  • 01:11:52 has a two bytes overhead and the number of characters that in your stored value. If you

  • 01:11:59 define var character max, it is same two bytes overhead and number of characters. If you

  • 01:12:05 define text, it has four bytes overhead and number of characters. If you define and charge

  • 01:12:13 uh, it has no uh overhead but it is defined with plus multiply two. Then there is and

  • 01:12:24 var character. Then there is binary and var binary and image. Okay, you see these are

  • 01:12:33 the types, then the numeric types. Bit okay, bit is very useful because uh we use bit data

  • 01:12:41 type for storing boolean values. You see if it is zero, it is false. If it is one, it

  • 01:12:46 is true. It can be also null. But in csharp it cannot be null. And then there is tiny

  • 01:12:53 int. Tiny. Int uh can hold between zero and 255. Then there is small int. You see it is

  • 01:13:02 silent by the way. Uh so this is equal to int 16 in uh c sharp. Then there is int. Then

  • 01:13:10 there is big int you see uh. However, this is not. This is also int 64 in c sharp. Then

  • 01:13:18 there is decimals. Decimals is really important. So with fixed precision and scale numbers,

  • 01:13:25 decimals are defined with p and s. Then there is numeric. Okay, let's read this decimals

  • 01:13:39 first. Fixed precision and scale numbers allows numbers from minus 10 to the power of 38,

  • 01:13:45 plus 1 to 10 to the power of 38. Minus 1. The p parameter indicates the maximum total

  • 01:13:52 number of digits that can be stored both to the left and to the right of the decimal point.

  • 01:13:56 P must be a value from 1 to 38. Default is 18. The s parameter indicates the maximum

  • 01:14:04 number of digits stored to the right of the decimal point. S must be a value from zero

  • 01:14:09 to p. Default value is zero. Okay, then there is numeric and it looks like same. I wonder

  • 01:14:19 if there is numeric here? yeah, we have numeric. And do we have decimal? Yes, we have decimal

  • 01:14:29 and numeric. So what is the difference between numeric and decimal? Let's see. Okay, let's

  • 01:14:50 read it. Actually someone has asked approximate numeric data types do not store the exact

  • 01:15:16 values specified for many numbers. They store an extremely close approximation of the value.

  • 01:15:22 Tech net: avoid using float or real columns in where clause search conditions especially

  • 01:15:27 the equals and less than greater than operators tech net: so generally because the precision

  • 01:15:36 provided by decimal is 10 e 38 to 38 digits if your number can fit in it and smaller storage

  • 01:15:42 space and maybe speed of float is not important and dealing with abnormal behaviors and issues

  • 01:15:48 of approximate numeric types are not acceptable. Use decimal. Generally

  • 01:15:59 numeric equals decimal 5 to 17 bytes. Exact numeric data type will map to decimal in dot

  • 01:16:05 net. Both have 18 0 as default. Precision scale parameters in sql server scale equals

  • 01:16:11 maximum number of decimal digits that can be stored to the right of the decimal point.

  • 01:16:17 Kindly note that money eight byte and small money four byte are also exact and map to

  • 01:16:22 decimal in dot net and have four decimal points. Msdn, decimal and numeric transact sequel

  • 01:16:28 msdn can be stored in any given address by default. Thank you. . . . . . . . . . . . . . . . . . . . . . . Okay,

  • 01:17:27 I didn't like any of the answers there. So I will check another one. Okay, so I think

  • 01:18:06 you should use decimal instead of numeric. Decimal is equal to decimal in C sharp. Okay,

  • 01:18:14 let's continue. And there is small money. Interesting. I have never used this. There

  • 01:18:24 is money. Okay, you see, if you use money, it can hold this kind of position. Then there

  • 01:18:35 is floating. Okay, then there is date time, which can hold date. With accuracy of 3.33

  • 01:18:46 milliseconds. Then there is date time too. With accuracy of nanoseconds. Small date time.

  • 01:18:53 Date. Okay, and time. And other things. As you use SQL Server, you will get to know them

  • 01:19:06 better. Okay, so, student name, I will define it as n var character. Why? There is also

  • 01:19:15 character and n var character. N means that you can hold non-Ansi characters. What I mean

  • 01:19:25 is, if you don't use n char, then you cannot save non-Ansi characters such as this one.

  • 01:19:44 So, you need to use non-Ansi characters. You have to use n version of character in SQL

  • 01:20:03 Server. Okay. So, n var character. How much character would be the person name? Let's

  • 01:20:12 say 200. And do we have a lot of notes? No. And then, what else do we have? We have email

  • 01:20:21 of the student. So, emails should be characters because they are all in English letters. I

  • 01:20:33 am also setting as 200 characters. And we have the gender. Gender is Boolean. Therefore,

  • 01:20:42 I will keep it as bit. I mean like this. So, let's say it's male. And do we allow nulls?

  • 01:20:55 No. We can also set default values. So, I will set the male character. Default value

  • 01:21:02 is 0. When you set default values, then if you don't provide the default value, the default

  • 01:21:09 value will be used obviously. So, you don't have to provide the value of default value

  • 01:21:16 having columns. If you don't set the default value and if you don't allow null, then you

  • 01:21:22 cannot insert records with nulls. Then, let's define another column which we will allow

  • 01:21:34 nulls. Something that students may not have or may have. And let's say what kind of feature

  • 01:21:48 we can add that can be null or not null. Let's say nickname. Okay. So, the nickname will

  • 01:22:05 be nvarCharacter and 250 and I will allow nulls. So, when I click save with Ctrl S or

  • 01:22:15 here, it will ask me the name of the table. I will name the table as tblStudents. The

  • 01:22:21 first table of our application is generated. When I click tables here and click refresh,

  • 01:22:33 you see it is here. Now, I can see the records inside it. How? Right click, select top. And

  • 01:22:40 it will return me the top 1000 rows by default. Like this with this query. And you see currently

  • 01:22:48 we have nothing. Okay, so what does this query mean? This means that there is select. Select

  • 01:22:54 means select. Top means top x results. So, we may have 10 million records in the table,

  • 01:23:03 but we only want to return top 1000. But top according to what if you wonder? It is by

  • 01:23:10 default sorting currently because we didn't sort our select with anything. And if you

  • 01:23:18 leave it to default sorting, each time you pick top x records, they may be different

  • 01:23:26 because you are not providing any sorting. And then, okay, this is the syntax. We provide

  • 01:23:33 the column names. If your column is something like this, then you don't need to put these

  • 01:23:44 brackets. However, if your column is, let's say something like this, then you have to

  • 01:23:52 provide the brackets, okay? Personally, I prefer to write column names like this, so

  • 01:24:02 I don't need to provide brackets as well, but you may use them with brackets. Okay,

  • 01:24:09 from where? From school database and from DBO and TBL students. By the way,: you don't

  • 01:24:19 have to type DBO in some cases, but in this interface, you have to write, okay. Alternatively,

  • 01:24:30 you can write something like this. Select star from TBL students like this, okay. So

  • 01:24:46 after you made a change to your database tables, then you go to edit and IntelliSense and refresh

  • 01:24:55 local cache, so IntelliSense will work better. Alternatively, you can close SQL Server Management

  • 01:25:03 Studio and reopen it. So now IntelliSense shows me the column names like this. Okay,

  • 01:25:11 first you should do your database options designed with SQL Server Management Studio

  • 01:25:23 because it is much easier than doing with code, then you can write your code. Okay,

  • 01:25:30 so let's open our application and generate some random data and insert it into our table

  • 01:25:37 first from SQL Server Management Studio. Okay, I click test, okay. So let's insert our first

  • 01:25:48 record. How am I going to do that? I am opening a new query window here. To insert, we use

  • 01:25:56 insert into. Insert into which table? Currently you see, my database is selected here, therefore

  • 01:26:03 I don't have to write something like this. Because my database is defined, therefore

  • 01:26:12 I don't need to type it. However, if it was something like this, then I would have to

  • 01:26:19 define a SQL DBO and TBL students. Okay, you see the difference in your programming. If

  • 01:26:27 you have defined your database in your query, we will see that, then you don't have to type

  • 01:26:36 this. However, if you didn't define your database name, like school, then you have to write

  • 01:26:43 the full path. Okay, this is about writing the full path of your table or not. So insert

  • 01:26:49 into TBL students. Okay, then I define the column names. Okay, which column names I will

  • 01:26:56 provide? I will provide student ID, then student name, then student email, and mail. I don't

  • 01:27:12 have to provide mail or nickname. Why? Because the mail has default value and nickname can

  • 01:27:20 be null. Okay, so I will write different cases. This is the first case. You see currently

  • 01:27:28 it is showing me as invalid object name. Why? Because the database is not selected, so I

  • 01:27:33 am selecting school. Then I type the values like this. Okay, now when you are providing

  • 01:27:41 a string value, you have to use beginning like this. Okay, what if you want to use single

  • 01:27:49 quote character, then you escape it like this. You see, so this one is escaping this one

  • 01:27:56 and this is the beginning of string and this is the end of the string. So let me show an

  • 01:28:01 example. The first one is integer, therefore I can just something like this or you can

  • 01:28:08 also define it as a string. It will be automatically converted into integer by the SQL server.

  • 01:28:16 However, it is better to write as integers. So let's write this one. Okay, whatever. It

  • 01:28:27 is not important. Something like this. Then you see I am separating values with comma.

  • 01:28:37 Then student name, so it is string. Therefore, I am writing student name like this. However,

  • 01:28:44 if I want to something like this. Then I have to escape this one like this. And since I

  • 01:28:53 have special characters, you better put an letter in front of your string and means that

  • 01:29:01 now you can insert non ASCII characters as well. So let's make some different examples.

  • 01:29:11 I will make it something like this. So this is non ASCII character. And let's write the

  • 01:29:24 email. Email is string too. Okay, let's write something like this. Okay, so when I execute

  • 01:29:39 it, when you click execute, it will execute all the queries written here. Or alternatively,

  • 01:29:45 you can choose the query like this and you can click execute this time. It will only

  • 01:29:51 execute the selected query. So I'm executing and here the result. It says that one row

  • 01:29:56 affected, that means that one row is generated because it is insert query. Then I will select

  • 01:30:04 the records here. Right click and select 1000 rows. Okay, I see my record is inserted into

  • 01:30:12 database. So let's see. Okay, it appears that it is able to insert this one. Maybe due to

  • 01:30:33 my collision set up or due to SQL Server management, a new version or let's try some others. Characters,

  • 01:30:40 maybe it is due to real characters. Okay, bigger eye, it is not existing in English.

  • 01:30:51 Let's try this. Okay, one another row. Let's refresh. Okay, it is added as well. Yeah,

  • 01:31:03 interesting. It is definitely automatically escaping. But you should always use n characters.

  • 01:31:18 Okay. Okay, so what does n means? What is the purpose of putting an n in front of function

  • 01:31:39 parameters in TSQL? It is both in function parameters or in string, so. It indicates

  • 01:31:49 a nationalized aka Unicode string constant. When dealing with Unicode string constants

  • 01:31:56 in SQL Server you must proceed all Unicode strings with a capital letter n, as documented

  • 01:32:02 in the SQL Server books online topic, using Unicode data. Okay, so it is coming from nationalized

  • 01:32:21 text. It was available in SQL 92 before Unicode even existed. So this is the meaning of n.

  • 01:32:28 Currently it is working in my SQL Server management studio, but previously it wasn't working,

  • 01:32:34 I am sure. So this is probably something new. So this is the first case. First example.

  • 01:32:41 And by default, they are provided as zero, as you can see. Okay, one moment. Okay, so

  • 01:32:52 this was the first version of insert. Then, now let's provide default value as well. Because

  • 01:33:03 it was being incorrect. Okay, and now the third version where we provide all column

  • 01:33:12 names. Nickname, let's say teacher. Okay, you see now I have to scroll horizontally.

  • 01:33:27 I think we can fix it with options. Provide text editor. Not sure though. All languages.

  • 01:33:44 Okay, word wrap. Okay, now it is wrapping and the final version. And in this case, we

  • 01:33:58 won't provide any column names, but you have to provide exactly the same number of inputs.

  • 01:34:06 This works. However, this would fail. Okay, this fails. This fails because we didn't provide

  • 01:34:16 exactly the same number of values. Let's try. I remember. Okay, you see. I will just comment

  • 01:34:35 this out like this. Okay, now let's execute. We can execute all of them with execute. You

  • 01:34:43 see all of them inserted. Now if we select, we can see all of them. And let's make some

  • 01:34:51 randomization so we can do some select and where queries. Okay, something like this.

  • 01:34:59 And I will also generate some random numbers. Okay, so. Okay, here. So let's add some randomization

  • 01:35:23 to IDs. Okay, each time different numbers on them. Oh, they are all zero. So. I see

  • 01:35:37 so it is generating between. Maybe. Since it was integer, it was getting. Different

  • 01:35:56 so let's use this method instead. This one. So let's make the, let's move to a percent.

  • 01:36:25 These are not the key issues I am just. Generating some random input so. You can see it. Actually,

  • 01:36:35 we can even append to. Perhaps name. I wonder if it will work. So I have to convert it to.

  • 01:36:48 String anyway, just something like this. Okay, we have some. Okay. Now you see we have 74

  • 01:37:02 records. And they are added with the values we have. So now let's make some select queries.

  • 01:37:12 Select. Then I have to define column names, which ones I have to. I want to select if

  • 01:37:18 I put star, it means that it will select. Everything from which they will students they

  • 01:37:24 will. Since school table database is selected. Then I don't have to write the full path.

  • 01:37:31 If it was something like this, then I would be have to. School. Dbo. TBS. Okay, now this

  • 01:37:38 will select everything as you see. Let's say I'm returning this to school. I want to select

  • 01:37:51 students. Let's say I want to select student ID. From students, so first I write the from

  • 01:38:02 then. I can also define it like. The student ID or. Like this, since there isn't any other

  • 01:38:12 table in my query and there isn't no duplicate names. So both would work. So you see it is

  • 01:38:20 just selecting the student. ID. This is the way of selecting selecting columns. I can

  • 01:38:26 also select like this. As you see. Okay, this is about select. We are defining the columns

  • 01:38:36 here. I can also format them as I want. For example. GG plus. I think student name. Should

  • 01:38:48 work. Let's see. Yeah, you see GG is appended. My string. Okay, as you can see, I think we

  • 01:38:59 can even append. Integers, however, to append it. Probably we need to cast this as a var

  • 01:39:10 character. I think there is cast method. And which parameters it is taking. Okay, there

  • 01:39:28 is nconvert. Target type expression date style small int. Maybe like this target type is.

  • 01:39:40 Var char. Expression is student ID. Okay. And then what is the next one. Okay. Date

  • 01:40:01 style small int. Okay, I don't know. We need it. Yeah, it is working as you see now. Okay,

  • 01:40:14 this is about select. We have seen the insert. Then we will see the var. Let's say you have

  • 01:40:23 millions of records and you have to. You want to only select 13 of them. Then we use var

  • 01:40:30 class. Okay, it is like select all from TBS students. Var student ID. Is bigger than let's

  • 01:40:40 say this number. So this is our like if class. This is bigger than. And then we select it.

  • 01:40:50 It will select only the records which has student ID bigger than this. Or I can select

  • 01:40:56 it like select all from TBS students. Var. Nickname. Not equal to null. Okay, if you

  • 01:41:05 type like this, this wouldn't work in SQL Server because. Null is not equal to null.

  • 01:41:11 You cannot compare nulls like this. This would, let's write it. Oh, okay. So what I need to

  • 01:41:33 do is I have to select it like this. From TBS students. Var. Nickname is not null. Okay.

  • 01:41:44 So you can use is or is not null. Okay. This returns is not null. I can also use as is

  • 01:41:52 null. And this will return null. You see. And I can use multiple var clauses such as

  • 01:42:04 student ID bigger than that. Or I can say bigger or equal. And I can say and or and

  • 01:42:14 or let's write or is not null. Okay, let's make it as and. So let's see this one. So

  • 01:42:25 this one returns either bigger than this student ID or not null here, as you can see. And alternatively,

  • 01:42:36 let's try this. So this returns only the records which are bigger than and is not null. This

  • 01:42:42 returns bigger than that or is not null. I can also make it like this or and is male

  • 01:42:56 equal to one. Okay, now in this case, you see you have or and and query. And how will

  • 01:43:04 it, how will it behave? You see it returns 52 because it is checking or and or is breaking

  • 01:43:13 and therefore you need to group the things that you want to or. Okay, something like

  • 01:43:23 this. So it will check either bigger than this and this. And then this rule. So this

  • 01:43:33 one returns 43. This one returns 52 and this one returns 16. So you see how you are writing

  • 01:43:45 your query affects your results. Now, finally, there is delayed query delayed from students.

  • 01:43:54 I can delete all records or I can use where such as I want to delete this particular record

  • 01:44:00 where student ID equal to this. So this will delete this record. Okay, so let's select

  • 01:44:17 the record and let's find it. Actually, let's select the record with this one. Select all

  • 01:44:26 from students where student ID equal to this. Okay, when I select it, it returns this record.

  • 01:44:36 And after I delete it, it will tell me that one row affected. That means that one row

  • 01:44:44 is deleted because it is delete query. And if I run it again, you see zero rows affect

  • 01:44:49 because it's already deleted. And when I select it, you see it is returning nothing. Okay,

  • 01:44:57 so these are the queries that save them as well. So you may want to look at them. However,

  • 01:45:07 it would be much better if you write them yourself. And over the time, you will understand

  • 01:45:17 better how to write queries. Okay, so in search queries. Okay, it says that save with other

  • 01:45:29 encoding. So I will save it as UTF-8. It appears that there is no UTF. Oh, here, here I will

  • 01:45:47 save it as UTF-8. Yeah, this should work. Okay, and then I will save this as well. Select

  • 01:46:02 where delete. Okay. Okay, now we have seen how to do queries from new query execute.

  • 01:46:14 And we can also edit rows. You see it allows me to edit top 200 rows. I can also change

  • 01:46:21 that. I think from designers. And here. Here you should remove this if you want to save

  • 01:46:41 some changes. Such as, for example, let me show you. I click design and I want to change

  • 01:46:50 this student email to, let's say, like this. When I click save, it says that saving changes

  • 01:46:57 is not permitted. The changes you have made require the following tables to go with the

  • 01:47:02 robot and recreated. You have either made changes to a table that can't be recreated

  • 01:47:07 or such. Then I go to options and I go to designs and here. I remove this checkbox.

  • 01:47:16 And I also increase the timeout because some timeouts and some changes may take too much

  • 01:47:24 time. Okay, then I click save and it is saved. Okay, and another thing is. I think maybe

  • 01:47:33 text editor, no. Here, okay. SQL Server, Object Explorer. You can change, for example, select

  • 01:47:44 top 1000 to top 5000. And you can change this edit to top 200, 2000 rows. And I can also

  • 01:47:56 change this to 5000 something like this. Okay, now when I right click, you see select 5000

  • 01:48:03 top rows. And when I click, I can edit top 2000 rows. I can change the values here or

  • 01:48:11 I can add here or I can right click and delete here. I can copy here and such. Okay, so these

  • 01:48:18 are the things that you can do with: SQL Server Management Studio. There are also other tools

  • 01:48:24 such as SQL providers and Azure Data Studio and such. However, there are more advanced

  • 01:48:30 things. I can also compose another table. As you can see, so you can have multiple tables

  • 01:48:38 as time goes and we progress through our lectures. We will see more about that. So now it is

  • 01:48:46 time to do these operations within our code. So it is a common mistake that students are

  • 01:49:00 writing inline code in their program. What I mean is, for example, you want to insert

  • 01:49:09 records into the database. And whenever you want to do that, you write that code there.

  • 01:49:20 It looks like we are reaching two hours. Maybe I should end the lecture here and we may continue

  • 01:49:29 next week. For example, I can change it here and after you make the changes, you have to

  • 01:49:37 click another row. So it will be updated. It is modified, but not saved. When I click

  • 01:49:44 here, it is now saved. Okay, this is an important thing. If you are changing Boolean, then you

  • 01:49:51 change it with zero. Okay, one second. Okay, I have to change it as false, I think. Oh,

  • 01:50:04 it says that it is not valid anymore. So I just escape, close and reopen. Okay, now working.

  • 01:50:20 You see, I can change the Boolean values with zero and true. However, when you are filtering

  • 01:50:28 your results as is meal equal to zero, it still works. When making queries, I wonder

  • 01:50:39 if this is working. Yeah, it is also working, you see. Okay, maybe it is either way works

  • 01:50:54 here in the application. Were there any differences? I am not sure. Probably there weren't any

  • 01:51:03 differences. Okay, let's see the execution plan as well. So when you click here, actual

  • 01:51:14 execution plan, it will show you how the plan works. It is an advanced stuff. It is doing

  • 01:51:21 table scan. Okay, because we don't have any indexes, we will see indexes later. Okay,

  • 01:51:28 so let's note this as well. Okay, how to install Microsoft SQL Server, of course, developer

  • 01:51:48 edition. Okay, how to install SQL Server Management Studio. How to compose table or let's say

  • 01:52:08 database with SQL Server. How to compose database and table. Okay, what is correlation and what

  • 01:52:25 difference it makes. Okay, how to write, insert, update, delete and select queries. Okay, by

  • 01:52:40 the way, we didn't show the update command. So I will show you that as well. So let's

  • 01:52:54 open a new query window and select top request. Okay, so when you're updating, either you

  • 01:53:04 have to have some unique values to update certain records or it will update everything.

  • 01:53:11 So what I mean is, let me show you. To update it, you write as update and then the updating

  • 01:53:18 table name. I will also record this as database, studio table or just table. Okay. Okay, okay.

  • 01:53:48 So update tblStudents set them set set means that which columns we will change. By the

  • 01:54:02 way, you can think this as values kept in an Excel table. It is very similar. However,

  • 01:54:11 in the background, they are very different, but from the usability perspective, I mean.

  • 01:54:19 So let's set the student name equal to new student. And email student email equal to

  • 01:54:29 leave email at hotmail com, for example. And if I don't write a VAR, it will change all

  • 01:54:40 records. Okay, because there is no VAR predicate. So let's try this. I am selecting this query

  • 01:54:51 and running. So it has affected 73 rows. When I select it, you will see that all records

  • 01:54:58 are changed to this. If I want to change this record, can I change it only that one right

  • 01:55:06 now? No, because this record has no unique identifiers. Because there are multiple records

  • 01:55:17 like this. Let me. Let me illustrate that. Okay, select the star from students where

  • 01:55:32 student ID is equal to zero. Sorry. And then student name is equal to new student. And

  • 01:55:59 you see I am using and predicate. Student email is equal to new email. Okay, is male

  • 01:56:11 and is male equal to one and nickname is not. Let's see how many duplicate records like

  • 01:56:22 that. Okay, there are seven. So whenever I make an update to each one of these roles,

  • 01:56:31 it would update all of them. I cannot update any of them because any particular of them

  • 01:56:39 because there is no unique identifier. However. For example, I can update this record probably

  • 01:56:47 because it's student. ID looks like unique. Let's check it out. From tblStudents where

  • 01:56:53 student ID is this. And when I select, you see there is only one row. Okay, I can I can

  • 01:57:02 update that particular. So students with unique student ID and have some mail. And then I

  • 01:57:18 write my condition as student ID is equal to this one. So you see, this is how it works.

  • 01:57:29 I can also add all records. Let me show you. Okay, so it has affected one row and I will

  • 01:57:36 write this as well. So you will understand. Okay, this will update seven records. Okay,

  • 01:57:46 so I'm adding all these where requirements. And I run it. You see seven rows affected.

  • 01:57:54 Okay, and let's also use or and in. Okay, so. Okay, students, let's say multiple students.

  • 01:58:09 Students. Okay, multiple. Okay, where student ID is this or this or student ID is this or.

  • 01:58:21 Student ID is this. Equal to this. So when I execute, it will update three rows. I could

  • 01:58:38 also write this query as. You see, it is automatically formatting. I wonder if we can auto format.

  • 01:58:49 Okay, let's see if there is auto format. Okay, there is format TSKL code tools. Okay, maybe

  • 01:59:11 it is external tool. Maybe we select code then. Okay, code snippet managers. This is

  • 01:59:27 from here. No, not this one. It says there is adding. Okay, anyway, not important right

  • 01:59:41 now. So what I'm going to do is you can also write this query as like the student ID in.

  • 01:59:47 When you type in, you can define multiple variables like this. Okay, here and here.

  • 01:59:58 Okay, so. When I run this query, you see it has affected three rows. So this is basically

  • 02:00:07 same as this one. Okay, you get the idea now. If you want to update particular records,

  • 02:00:15 then you have to have a unique identifier to that record. Database records. Okay, so

  • 02:00:57 let's comment this. If you want to update, delete, insert, select particular database

  • 02:01:03 records. Then you have to have a unique identifier or a certain combination of multiple columns

  • 02:01:10 that uniquely identifies that particular records. This is the way you can do it. Okay, we will

  • 02:01:20 continue next week. I am also update and let's say update queries as well. Okay. When to

  • 02:01:43 write pull paths, how to make insert, update, delete, select queries. By the way, there

  • 02:02:06 is no insert. And Okay, I think we are over two hours. Okay, at the home, please write

  • 02:02:42 everything yourself as I am doing, watching me while watching the video and not just use

  • 02:02:49 the copy and not just use the code I am uploading to our GitHub repository. So let me upload

  • 02:02:57 the code to repository. Okay. If you have any questions, please ask me from this court,

  • 02:03:36 or from my email. And you know that on our discord, higher years students can also help

  • 02:03:46 you. The databases are extremely important part of programming. So you should pay extra

  • 02:03:54 attention to database related lectures. Okay, you see the code is uploaded. Now you can

  • 02:04:00 access it. The txt files, creative files, everything is here. Alright, so we have shown

  • 02:04:12 everything. We have shown so many things in this lecture. This is the end of the lecture.

  • 02:04:17 Hopefully see you next week.

Clone this wiki locally