Introduction To SQL
Introduction To SQL
DATABASES
INTRODUCTION TO SQL
Relational databases
A relational database defines relationships between tables of data inside the database.
Possibly the biggest advantage of a database is that many users can write queries to gather insights from the data at
the same time.
More storage than spread sheets.
Can be secured with encryption.
Tables
Schemas
o Schemas are often referred to as "blueprints" of databases.
o A schema shows a database's design, such as what tables are included in the database and any relationships
between its tables.
Database storage
o Finally, let's discuss storage. The information we find in a database table is physically stored on the hard disk
of a server.
Servers
o Centralized computers that perform services via requests made over a network. In our case, the service
performed is data access, but servers are also used to access websites or files stored on the server.
o Any computer can be a server if it is set up to provide a service, even a laptop!
Introducing to queries
Keywords are reserved words used to indicate what operation we'd like our code to perform.
BEST PRACTICES
o To end the query with a semicolon to indicate that the query is complete.
o We also capitalize keywords while keeping table and field names all lowercase.
o We can use * to select all field names.
Writing queries
Alias (Aliasing). Rename columns in our result set.
DISTINCT. Return unique combinations of a field or multiple fields.
Views.
o A view is a virtual table that is the result of a saved SQL “SELECT” statement.
o A benefit of views is that when accessed, views automatically update in response to updates in
the underlying data.
PostrgreSQL
o The POSTGRES project, led by Professor Michael Stonebraker, was sponsored by the Defense
Advanced Research Projects Agency (DARPA)
o Free and open-source relational database system
o Created at the University of California, Berkley
o Refers to both the PostgreSQL database system and its associated SQL flavor.
SQL Server
o Has free and paid versions
o Created by Microsoft
o T-SQL (Transact-SQL) is Microsoft’s flavor, used with SQL Server databases.
o T-SQL vs SQL. T-SQL is a variant of SQL, with some additions like Stored Procedures and Triggers.
PostgreSQL: LIMIT 2;
SQL Server: top(2)