Skip to content

Instantly share code, notes, and snippets.

@StaniTr
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StaniTr/1e71ab786743febc5c57 to your computer and use it in GitHub Desktop.
Save StaniTr/1e71ab786743febc5c57 to your computer and use it in GitHub Desktop.
Part1 - Create DB, Create Table, Import Data From CSV
USE master
CREATE DATABASE sqlPuzzleSessions
ON
--The model database is used as the template for all databases created on an instance of SQL Server.
/*Primary data file - contains the startup information for the database; points to the other files in the database.
User data and objects can be stored in this file or in secondary data files.
Every database has one primary data file. (.mdf)*/
-- Because MAXSIZE is not specified, the files can grow to fill all available disk space.
(NAME = puzz,
--puzz - primary file, size = size of the primary file in the model database
--transaction log file - automatically =25%*max(primaryFileSize, 512 KB)
FILENAME = 'D:\SQLTraining\SQLpuzzle\sqlPuzzleSessions.mdf')
GO
CREATE TABLE puzzSessions(
--Create table
Session_ID INT,
"Timestamp" DATETIME,
ActionName VARCHAR(6)
)
--insert data from 'sql_puzzle_sessions.csv'
BULK INSERT puzzSessions
FROM 'D:\SQLTraining\SQLpuzzle\sql_puzzle_sessions.csv'
WITH
(
FIRSTROW = 2,
FIELDTERMINATOR = ',', --CSV field delimiter
ROWTERMINATOR = '\n', --Use to shift the control to next row
TABLOCK
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment