Skip to content

Instantly share code, notes, and snippets.

@StaniTr StaniTr/Part1

Last active Aug 29, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.