No video

7 Mistakes Beginners Make with SQL

  Рет қаралды 18,859

Database Star

Database Star

Күн бұрын

Пікірлер: 32
@angelbear_og
@angelbear_og 2 жыл бұрын
Another (IMO better) way to do #5 is just write it as a SELECT query to start. You need to validate your records before updating/deleting anyway. Once it's correct you can replace SELECT with DELETE; or write UPDATE/SET clause without the FROM and WHERE; and copy/paste the WHERE from the SELECT query. I often end up with something like this, and once my result set is what I want I flip the commenting from UPDATE to SELECT: select COLA, COLB, COLC from TBLA --update TBLA -- set COLA = x -- , COLB = y -- , COLC = z where CRITERIA1 and CRITERIA2 etc...
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Great advice! Yeah checking the records you are about to change from an Update or Delete by running a Select is very helpful.
@mostafa2199
@mostafa2199 Жыл бұрын
Your channel helped (and still) me a lot while learning SQL Thanks man ♥️ Keep the good work up
@DatabaseStar
@DatabaseStar Жыл бұрын
Glad it’s been helpful!
@olaoluwaadeosun2942
@olaoluwaadeosun2942 2 ай бұрын
Bunch of thanks
@DatabaseStar
@DatabaseStar Ай бұрын
You’re welcome!
@TheInternetFan
@TheInternetFan 2 жыл бұрын
what command will reveal all the columns/attribute of a table without using "SELECT * FROM table" in order to avoid mistake n.1?
@DatabaseStar
@DatabaseStar 2 жыл бұрын
It depends on your database, but you can usually query the data dictionary to find this information. Something like SELECT * FROM information_schema.columns WHERE table_name = 'person'; - this could work on MySQL to see column information. Other vendors (Oracle, SQL Server, Postgres) have similar features.
@utkarshgupta6091
@utkarshgupta6091 2 жыл бұрын
Hello sir. Are you planning to cover window functions like over-partition by clause and topics like cte? please consider the employee database that you used in your udemy course as it will be easier to understand from it. please cover these topics.
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Good idea! I have it on my list of things to cover in future videos.
@luupski
@luupski Жыл бұрын
Nothing wrong with using select * if you do not know all the columns in the table. And to prevent getting to much data, just limit the rows with 'ROWNUM < 10' for example, or like 'fetch first 10 rows only'
@DatabaseStar
@DatabaseStar Жыл бұрын
Good point, yeah using Select * is helpful to see all of the columns. Using it to find out about the rows and columns is a good way to use it. Using it in production - different story!
@luupski
@luupski Жыл бұрын
@@DatabaseStar i do this in production daily and limit the result to 1 row I have to use a couple of dozens of tables and can't remember all of the columns in all those tables, only the most common ones used. So i use it whenever i have joins, or want to see if any additional columns help to present better data. Sure i can go into an object browser and go and look at the columns there, but that takes much more time. As long as it is used wisely i see no issue of using select * in production
@buraktiras93
@buraktiras93 2 жыл бұрын
Thanks!
@DatabaseStar
@DatabaseStar 2 жыл бұрын
No problem!
@romanpikulenko
@romanpikulenko Жыл бұрын
The suggestion #2 is absolutely wrong and it may and certainly will cause your application to halt. Let's imagine a real application consisting of something like follows: table Orders ( OrderId primary key, -- ~ 20 columns with data ) table OrderItems ( OrderId int reference to Order, ProductId int reference to Product, primary key (OrderId, ProductId) -- ~ 8-10 other columns with data ) table Products ( ProductId primary key, -- 10 other columns with data ) Now, we need to fetch information about 10 orders with their items and products to construct business logic models. Let's assume that each order has 20 items. In case of one select query which joins all related tables and return one result we will have: 200 rows - 10 orders * 20 order items each row consists of 40 fields - 20 field of order + 10 field of order item + 10 field of product So that we will have 200 * 40 = 8000 values fetched from the db if we execute three separate queries to receive the same data table by table, we will have: 10 * 20 = 200 values for orders 20 * 10 * 10 = 2000 values for order items 20 * 10 * 10 = 2000 values for products and it is only of all products are unique throughout all orders which is very rear case. So that we will have 200 + 2000 + 2000 = 4200 and even less values fetched from the db. And this difference grows very quickly as information from new tables are needed because they have to be joined to the one select statement. The main problem of a join operation that it duplicates information in rows, this is the reason of difference in field count mentioned above. Moreover, one statement approach does not allow to use caches to reduce common amount of data needed from db.
@DatabaseStar
@DatabaseStar Жыл бұрын
Thanks for the detailed comment. Are you saying it's bad to join separate tables because it could cause your application to halt? If so, I believe you have been mistaken. Your example indicates 200 rows would be returned, with data from three tables. This is a tiny amount of data for a database to handle, and even in a high-volume system, there are features and techniques that can be used to improve the performance if it suffers. Your scenario of the number of values is OK as well. You may not need to select all values in all tables, but if you do, and you need to select 8000 values (200 rows x 40 values), this is also not a problem for the database to handle. If you execute three separate queries, there may be fewer fields returned, as you've shown. But you would still need to combine the results together to show the correct order and product data. If this is not done in the database, you'll need to do it in the application, which is not ideal and would still take some processing. There is no problem with returning common data if it relates to different rows. You'll have to combine data in one way - either in the database or the application. The database is designed specifically to do this, so it's better to do it there than the application.
@Keiktu
@Keiktu 2 жыл бұрын
Subscribed :)
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Thanks!
@tsunamio7750
@tsunamio7750 6 ай бұрын
7:52 NO NO NO NO! YOU DO NOT RUN AN UPDATE OR DELETE CLAUSE WITHOUT CHECKING WITH SELECT FIRST! REDO THIS ADIVE I BEG YOU! Write a SELECT statement and see if the returned data is truly what you wanted to mofiy. Then only then, replace SELECT with UPDATE OR DELETE.
@DatabaseStar
@DatabaseStar 6 ай бұрын
Great point! Yes you should always run the query as a Select first to see the rows that are impacted by the Delete or Update. Then it’s simple to replace it with a Delete or Update. My tip about always adding a Where clause to a Delete or Update still stands - perhaps I should have added your suggestion to this video to make it better.
@ayman4318
@ayman4318 2 жыл бұрын
I need explanation for indexing
@DatabaseStar
@DatabaseStar 2 жыл бұрын
I created a video on Indexing about a month ago that could be helpful.
@andrewkamoha4666
@andrewkamoha4666 Жыл бұрын
*Mistake 3 - Not using functions* 4:17 "SQL includes many in-built functions to process data and give you a result." Where is the *MEDIAN* function ????
@DatabaseStar
@DatabaseStar Жыл бұрын
The Median function is not included in many vendors of SQL, but some Google searching indicates it's possible to write a function to calculate it.
@mazinalyousef5814
@mazinalyousef5814 5 ай бұрын
No 5 is disaster
@DatabaseStar
@DatabaseStar 5 ай бұрын
Yeah it is!
7 Useful SQL Features You Probably Don’t Know
19:41
Database Star
Рет қаралды 4,6 М.
When to Use a Subquery in SQL
8:50
Database Star
Рет қаралды 32 М.
Harley Quinn lost the Joker forever!!!#Harley Quinn #joker
00:19
Harley Quinn with the Joker
Рет қаралды 28 МЛН
Идеально повторил? Хотите вторую часть?
00:13
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 18 МЛН
Box jumping challenge, who stepped on the trap? #FunnyFamily #PartyGames
00:31
Family Games Media
Рет қаралды 33 МЛН
SQL Indexes - Definition, Examples, and Tips
12:14
Database Star
Рет қаралды 74 М.
Database Design for School Students for an Entire School
18:34
Database Star
Рет қаралды 22 М.
How long does it take to MASTER SQL?
9:57
Jay Feng
Рет қаралды 9 М.
Database Design for Facebook: A Social Network Database Example
11:15
Are you making this #1 SQL Error?
14:19
Data Wizardry
Рет қаралды 2,2 М.
SQL Window Functions: Explained (with examples)
9:11
Database Star
Рет қаралды 33 М.
How to Design a Database
10:57
Database Star
Рет қаралды 54 М.
Relational vs. Non-Relational Databases
8:12
IBM Technology
Рет қаралды 105 М.
I've been using Redis wrong this whole time...
20:53
Dreams of Code
Рет қаралды 353 М.
Complex SQL Query: Watch Me Write It
15:10
Database Star
Рет қаралды 6 М.
Harley Quinn lost the Joker forever!!!#Harley Quinn #joker
00:19
Harley Quinn with the Joker
Рет қаралды 28 МЛН