Posts

Showing posts from January, 2022

SQL, the wildcard characters of the LIKE operator (%, _ , [] and ^)

Image
Hi Guys, Today a quick and easy post to answer a question that was asked to me some time ago. We will talk about the wildcard characters of the like operator . In its simplicity I think it is useful to who is entering the world of the SQL language. Enjoy the reading! Wildcard characters of the LIKE operator SQL ANSI LIKE operator has different wildcard characters which are: The percent sign % The underscore _ The square braket [^] and []   Their use is very simple!     The percent sign (%) wildcard The percent sign (%) allows you to find if a substring is contained within a string.   For example we can write the following query: SELECT * FROM ITEMS WHERE NAME LIKE '%AD%' This statements will return all the rows of items table where the field name contain the string "AD" in any position.  For example:   R AD IO BL AD E AD VERTISING The underscore ( _ ) wildcard Looking at the following statement the underscore wildcard allows you to find all the rows of the

A bit of theory of databases: The Halloween problem and the Table Spool

Image
Hi Guys, Welcome to this second post of the year. Today we will talk a little bit of theory, we will talk a little bit of database theory in general and therefore not specifically of our SQL Server. Enjoy yourselves!   The Halloween problem I don't know about you but " Halloween problem " makes me think of one of those old fairy tales that always hide a wise warning, one of those fairy tales lost in a past time which in our case is however the period in which relational databases were born and started to develop ... but let me tell you the whole story! This story begins around the mid-1970s. Ted Codd, a researcher working at IBM, had conceived relational databases a few years earlier. Also in those years both the idea of ​​ data normalization (who does not remember the third normal form learned at university?) And the ACID properties of transactions (we talked about it here) were born. It was the golden age of databases but at the same time pioneering! But let's go

SQL Server, how to save images and attachments in the database. Is better to store images into the database or into the filesystem?

Image
Hi Guys, This is the first post of the year and i want to do my very best wishes for a great 2022! I hope it's a year of joy, peace and happiness for everyone! Well, this year we will start with a question!  Where is it better to save images and attachments? ...within the database or on the file system? yes but, some might ask.  How can I save images and attachments in the database? ..easy. Enjoy the read mates! Read and save images and attachments into the database Suppose we have a table that contains data relating to our products. One possibility is to store the image of our product in a column. In our example the table will have this structure: CREATE TABLE Products ( Id int identity (1,1) PRIMARY KEY NOT NULL, Code Varchar (20), ImageProduct VarBinary (MAX) ) Our image will be stored into the ImageProduct field of type VarBinary . Obviously in that same field we can store everything we want, a binary file, an application, an attachment and so on .. The first thing