An in­tro­duc­tion to SQL

Linux User & Developer - - Tutorial -

SQL, the Struc­tured Query Lan­guage, is an al­most uni­ver­sally used lan­guage for speak­ing to re­la­tional data­bases and gath­er­ing in­for­ma­tion from them. A database is made up of ta­bles – grids, like the one shown in Fig­ure 3 – and SQL is a very ex­pres­sive lan­guage for gath­er­ing in­for­ma­tion from these ta­bles. Be­sides the bare data ta­bles, we can form other ta­bles, called queries, whose val­ues are com­puted from the ex­ist­ing ta­bles, by writ­ing ap­pro­pri­ate SQL state­ments.

The most ba­sic SQL key­word is SE­LECT, which gets in­for­ma­tion from a num­ber of col­umns. So SE­LECT * FROM Videos; gets us the en­tire Videos ta­ble, while SE­LECT Ti­tle FROM Videos; gets us just the Ti­tles col­umn. We can place con­straints on these queries us­ing the WHERE key­word: for ex­am­ple, SE­LECT ID FROM Videos WHERE Ti­tle = 'Trip to the zoo'; gets us a list of IDs of videos with the given ti­tle.

An­other com­mand we use is COUNT: en­clos­ing a query in­side COUNT col­lapses the re­sult­ing ta­ble to its num­ber of col­umns. For ex­am­ple, SE­LECT COUNT(ID) FROM Videos; will get us the num­ber of videos in our col­lec­tion.

Newspapers in English

Newspapers from UK

© PressReader. All rights reserved.