Posts

Showing posts with the label Databases

Getting started with SQL Server Management Studio

Image
A few instructions on how to fire up SQL Server Management Studio (SSMS) in order to create a database, create a database table and perform various operations Creating a new database Open SSMS, right-click on Databases and select New Database... Give the database a name ('People' in this example) and select OK: Creating a new database table In the Object Explorer, select the database you created, right-click on Tables and select Table... (or New Table... in more recent versions of SSMS) You can fill in the column names and their data types like so Save the table by selecting Ctrl+S or via File > Save Table Making a column a primary key Select the column (in this case the column id) Right click and select Set Primary Key: So that the symbol for the primary key then appears in the column as shown: Also make sure the column property 'Is Identity' is set to Yes for id Unable to modify the database table? In some versions of SS...

How to join multiple tables with multiple keys / columns in SQL

Image
Some short instructions on how to accomplish a join on three or more SQL database tables but also using multiple keys/columns as well. Good StackOverflow reference: https://stackoverflow.com/questions/24639504/mysql-join-3-tables-using-multiple-columns-keys Three different tables used: 1. UserDivisions An old legacy table containing Division and it's ID: 2. MediaCategoryDivisionMap This table maps the Division ID of the first table to the Category ID of a newer MediaCategories table: 3. MediaCategories Finally the newer table that uses a Category ID: I wish to use the Division IDs in table UserDivisions in order to extract the equivalent Category IDs they are mapped to in MediaCategoryDivisionMap and therefore obtain the new Name contained in the MediaCategories table. As the StackOverflow post states "INNER JOIN creates a new result table by combining column values of two tables (A and B) based upon the join-predicate. The query compares each row ...