SQLUSA.com
SQL SERVER 2008 GRAND SLAM
FREE TRIAL  CLICK HERE TO ORDER  SEARCH
SQL JOBS SQL Server Training Scripts JOB BANK
  SQL Server 2008 Training Scripts  
  SQL Server 2005 Training Scripts  
News SQL Server Articles SQL Format

How to keep track of the stock market?

Execute the following Microsoft SQL Server T-SQL example scripts in SQL Server Management Studio Query Editor to setup tables for historical stock price tracking.


------------
-- Microsoft SQL Server stock price database architecture
------------
USE AdventureWorks;
GO
-- SQL table create for Stock Exchanges
CREATE TABLE Exchange (
  ExchangeID TINYINT    IDENTITY ( 1 , 1 )    PRIMARY KEY,
  Name       VARCHAR(64),
  DateModified DATETIME    DEFAULT (getdate()))
GO
 
-- MSSQL INSERT INTO - populated Exchange table
INSERT Exchange (Name) VALUES('New York Stock Exchange')
INSERT Exchange (Name) VALUES('NASDAQ')
GO
 
-- Test Exchange table population
SELECT *  FROM   Exchange
GO
/*
ExchangeID  Name  DateModified
1     New York Stock Exchange 2009-03-03 19:17:39.093
2     NASDAQ      2009-03-03 19:17:39.093
*/
 
-- SQL table create for historical stock prices
CREATE TABLE StockPrice (
  StockPriceID INT    IDENTITY ( 1 , 1 )    PRIMARY KEY,
  TradingDate  SMALLDATETIME,
  ExchangeID   TINYINT REFERENCES Exchange(ExchangeID),
  Symbol       CHAR(6),
  [Open]       SMALLMONEY,
  High         SMALLMONEY,
  Low          SMALLMONEY,
  [Close]      SMALLMONEY,
  Volume       INT,
  DateModified SMALLDATETIME    DEFAULT (getdate()));
 
GO
 
-- Dummy data - historical stock price for a day
-- T-SQL insert into table
INSERT INTO StockPrice
      (TradingDate,
       ExchangeID,
       Symbol,
       [Open],
       High,
       Low,
       [Close],
       Volume)
VALUES('2018/11/19',1,'IBM',76.0,77.0,75.0,76.2,11222444)
GO
 
SELECT *  FROM   StockPrice
GO
/*

StockPriceID TradingDate ExchangeID Symbol Open High Low Close Volume DateModified
1 11/19/2018 0:00 1 IBM    76 77 75 76.2 11222444 3/3/2009 19:18

*/
 
-- Cleanup
DROP TABLE dbo.StockPrice
DROP TABLE dbo.Exchange

 

------------

Order SQL 2008 GRAND SLAM Today!
SQLUSA.com Home Page
SQL Server Training at www.sqlusa.com.
SQL Server 2008 Video Training at www.sqlusa.com.
SQL Server 2005 Training Videos at www.sqlusa.com.
Microsoft SQL Server 2000 Training Videos at www.sqlusa.com.

FREE SQL & Business Intelligence / OLAP Short Videos on YOUTUBE.com

Microsoft Community Contributor 2011
Invest in Your SUCCESS!

Search SQLUSA FREE SQL Server Articles & FREE T-SQL Scripts


Copyright 2005-2011, SMI Corp. All Rights Reserved.

SQL Server 2012 is a program product of Microsoft Corporation.
SQL Server 2008 is a program product of Microsoft Corporation.
SQL Server 2005 is a program product of Microsoft Corporation.
SQL Server 2000 is a program product of Microsoft Corporation.