guides for installing ms sql server and creating your...

14
Guides for Installing MS SQL Server and Creating Your First Database Installing process Please see more guidelines on installing procedure on the class webpage 1. Make sure that you install a server with a matching version of Visual Studio in .NET First before installing any SQL Server. Download all the package together either 2016, 2014 or 2012 SQL Server (any edition is fine, not BI for this lab now, you can install it later) Make sure to install every components in the package - ODBC, Server, Clients, gateway,.... Name of Client is SQL Server Management Studio. 2. When installing a server, make sure to choose to 1) Follow Window Authentication to login and 2) the SQL server started automatically when your hosting system starts. 3. Check Control panel -> Computer management -> Service to see your SQL server is up and running, if not, start it manually there. If you don’t see SQL Server there in the service list, it means that you didn’t install the server in your system. Remove all by uninstalling program (NOT by you manually), then reinstall ALL the components in the package that the DreamSpark site provides. Once everything is installed, then 4. in Program -> 2016 or 2014 MS SQL Server, start MS SQL Server Management Studio which is an interface for both the sql server running on your host system and a client where you can type and execute SQL queries. If you need anything else, check MS site (or google it, you will find the site) for any info to install, everything is there. It will work only when you are a part of an Administration group of the host system. If you install the server in your system and you choose the option that a server get your OS user id and password, by default, your SQL server put your user id into the Admin group. If you are not, try to add yourself into Admin group in the database server in the host system in Control panel -> (Computer) System Management -> User management. For the Installation step for 2014 SQL Server step by step: You can find any related info here including Pre-requirement and all the components to install together. http://msdn.microsoft.com/en-us/library/ms143219.aspx

Upload: hoangnguyet

Post on 13-May-2018

225 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Guides for Installing MS SQL Server and Creating Your ...eecs.csuohio.edu/~sschung/cis612/GuideForInstallingMSSQLServerAll… · Either 2012 VS with 2012 SQL Server or 2013 VS with

Guides for Installing MS SQL Server and Creating Your First Database Installing process Please see more guidelines on installing procedure on the class webpage 1. Make sure that you install a server with a matching version of Visual Studio

in .NET First before installing any SQL Server. Download all the package together either 2016, 2014 or 2012 SQL Server (any edition is fine, not BI for this lab now, you can install it later) Make sure to install every components in the package - ODBC, Server, Clients, gateway,.... Name of Client is SQL Server Management Studio. 2. When installing a server, make sure to choose to 1) Follow Window Authentication to login and 2) the SQL server started automatically when your hosting system starts. 3. Check Control panel -> Computer management -> Service to see your SQL server is up and running, if not, start it manually there. If you don’t see SQL Server there in the service list, it means that you didn’t install the server in your system. Remove all by uninstalling program (NOT by you manually), then reinstall ALL the components in the package that the DreamSpark site provides. Once everything is installed, then 4. in Program -> 2016 or 2014 MS SQL Server, start MS SQL Server Management Studio which is an interface for both the sql server running on your host system and a client where you can type and execute SQL queries. If you need anything else, check MS site (or google it, you will find the site) for any info to install, everything is there.

• It will work only when you are a part of an Administration group of the host system. If you install the server in your system and you choose the option that a server get your OS user id and password, by default, your SQL server put your user id into the Admin group. If you are not, try to add yourself into Admin group in the database server in the host system in Control panel -> (Computer) System Management -> User management.

For the Installation step for 2014 SQL Server step by step: You can find any related info here including Pre-requirement and all the components to install together. http://msdn.microsoft.com/en-us/library/ms143219.aspx

Page 2: Guides for Installing MS SQL Server and Creating Your ...eecs.csuohio.edu/~sschung/cis612/GuideForInstallingMSSQLServerAll… · Either 2012 VS with 2012 SQL Server or 2013 VS with

https://www.youtube.com/watch?v=p3xcoLVNFho For installation step for SQL Management Studio with 2014 SQL Server (Note that this is for an Express version), there is a video guide here. https://www.youtube.com/watch?v=eGFdh_D0lYs One issue could be coming from installing SQL Server in Window8. Check the site for info. Depending on which one(Window 8 or Window 8.1) you are setting up a SQL Server on http://support.microsoft.com/kb/2681562 My suggestion for this issue is choose Window 7 to install to stay away from this kind of issue until they announce a complete solution for the issue. If that is not an option for you, then it is probably worth trying their most recent Service Pack for window 8 provided by their site to see it resolves the issue. Note that apart from the issue with Window 8, even on window 7, you have to match a version of Visual Studio and a version of SQL Server to install. Either 2012 VS with 2012 SQL Server or 2013 VS with 2014 server. They added a lot of new features and changed some design in each 2012 and 2014, so some of them are not compatible to install together. Any SP (Patch work) wouldn't resolve this issue. Your another issue in using SQL Server to create a database: Without knowing what you did in the process of creating a database, I can guess two causes: 1. Which version of SQL Server, try 2014 or 2012. The newest 2015 still seems not be stable. Check your Visual Studio version to match with SQL server. 2. In DreamSpark site, they require you to burn the downloaded into CD, so you install the SQL Server from CD. If you can't burn CD, then install 7-Zip (Make sure you download from a 7-zip site : http://www.7-zip.org/ not to get virus) then you can unzip the downloaded zip file by right clicking on the file to extract. http://www.7-zip.org/ 3. Your internet security setting to allow Active X There are a lot of instructions and trouble shooting guides for installation, google it to search those that is matching with your version and your OS. In MS TSQL, hitting the Return key is not for Submitting and getting your query Executed. To Submit a Query that toe be executed, issue GO command in the next line or hit the Execute button in your MS SQL Management Studio. You have to change your current database to Company with Use Company; GO after creating the database in the master level. Or setting in SQL management studio overwrites Use command in your query script, so set your current database to Company once you create it in the drop down list on the top corner of the Left side of Management Studio. By default, it is set to master when connect to the server first.

Page 3: Guides for Installing MS SQL Server and Creating Your ...eecs.csuohio.edu/~sschung/cis612/GuideForInstallingMSSQLServerAll… · Either 2012 VS with 2012 SQL Server or 2013 VS with

At master level, create a database first, which means you have to Execute it first ( either by hitting Execute button or type Go in the next line in your script (script means the query editor where you can write multiple queries then execute them at once) then in a separate query, issue Use database-name you just create. Make sure you got MSG from your server that the database is created, then you can submit Use database command. See the attached scripts help. Just to see how to use USE, GO, Create Database. Don't worry about the rest of the long list of option and alter stats there. One more tip. If you have any installation issues, which are usually coming from version mismatch between the components, no point to try to fix. Most of time, not working. Remove all then freshly reinstall them. Note that you have to let the uninstalling program (by MS ) or Remove Program by your system do all the uninstalling process. Never do it manually.

Some Trouble Shooting Tips and guides: Resolution for the Issue being stuck on a step called

"Install_WatsonX86_Cpu32_Action" during Installing SQL Server 2014 on a

Windows 10 PC

Issue: (This issue may not be seen any more)

During installing SQL Server 2014 on a Windows 10 PC, the installer got stuck on a step called

"Install_WatsonX86_Cpu32_Action" for hours.

Resolution:

I found that inside Windows Task Manager, there were more than one processes with the name

'Windows Installer' running (attached a screenshot of this below). After restarting the installation

process a few times, I decided to end the 'Windows Installer' process when it got stuck. Much to

my amazement, it continued installing past the point of being stuck.

I had to do this three more times before it installed fully, each time deleting the extra 'Windows

Installer' processes (I attached a picture of this as well).

Page 4: Guides for Installing MS SQL Server and Creating Your ...eecs.csuohio.edu/~sschung/cis612/GuideForInstallingMSSQLServerAll… · Either 2012 VS with 2012 SQL Server or 2013 VS with

Tips for Errors from Running and Connecting to SQL Server after

Installation

1. First, Check it out in Control Panel -> Administrative Tool -> Service to see your SQL

Server started. If not, start it manually there. 2. Your server is running but you can't connect to the server, then it is more likely a

problem from access control with your user id and pw. Somehow the server can not

recognize your id and pw (Assuming that the internet connection on your laptop is

good). Make sure that you install it with the option to pick up your user id and pw from

your Window OS. 3. If you didn’t choose that option when installing or you are not sure then go to

Control Panel -> Administrative Tool -> Service then Right Click on your SQL Server

then click on Properties -> General or Log On option , then you can change the starting

option there as below.

4. Choose Log On menu to change your user id and pw. 5. See Help there or search Online documentation for further detail.

Page 5: Guides for Installing MS SQL Server and Creating Your ...eecs.csuohio.edu/~sschung/cis612/GuideForInstallingMSSQLServerAll… · Either 2012 VS with 2012 SQL Server or 2013 VS with

Right Click on SQL SERVER then Click on Properties to get to the following windows:

Page 6: Guides for Installing MS SQL Server and Creating Your ...eecs.csuohio.edu/~sschung/cis612/GuideForInstallingMSSQLServerAll… · Either 2012 VS with 2012 SQL Server or 2013 VS with
Page 7: Guides for Installing MS SQL Server and Creating Your ...eecs.csuohio.edu/~sschung/cis612/GuideForInstallingMSSQLServerAll… · Either 2012 VS with 2012 SQL Server or 2013 VS with

FAQs on installation of SQL Server

Q: I followed the instructions attempting to download the SQL Server standard from the Imagine

website but ran into an issue. The earliest version that I am able to find available on the website

is 2016, which does not support windows 7. The only computer I have access to runs a windows

7 system. I wanted to make sure that installing the 2014 express edition from the official

website would be acceptable.

A: Looks like MS just removed all the 2014 SQL server from the Imagine site from this semester.

Yes, It is Ok to install 2014 express for now.

Page 8: Guides for Installing MS SQL Server and Creating Your ...eecs.csuohio.edu/~sschung/cis612/GuideForInstallingMSSQLServerAll… · Either 2012 VS with 2012 SQL Server or 2013 VS with

However, for your study later, there are a few ways to use SQL 2016 server on the given

Window 7 when SQL 2016 server can't be installed on Window 7 directly.

1. Get a student account on MS Azure cloud, they are free, you can set up a SQL server 2016 on

VM there. It is already configured, so not much learning but you will have a chance to explore an

Azure option.

2. If your laptop have enough Memory, install Oracle VM with Window 10 and 2016

SQL Server. If this is possible, it will be the exactly same platform.

3.

Q: I downloaded Oracle’s VirtualBox VM and setup the Windows 10 iso. I gave it 4 GB of

memory and 32 GB of fixed disk-space and use it at a scaled, small screen. However, every time I

use it, it is extremely glitchy and eventually just freezes until I shut it down. Is there an easy fix

or would I be better off to purchase VMWare Fusion or Parallels Desktop?

A: Looks like your default memory space (RAM) either for VM and/or your host system is too

small. It is a common problem, you need to set up with much more memory and disk space as

much as possible. There is a way to increase it when setting up to configure VM. Search for it.

No need to buy VMWare nor a parallel desktop.

Q: When i install Visual Studio enterprise 2017 I have many options

that I can select to install such as, game development with unity, and

desktop development with C++ and other stuff. I didn't see ANYTHING

about SQL server development on that page. I saw an option to install SQL

server express on the individual components page but I assume I don't

need that as I am already getting SQL server standard. Also the SQL

server standard download had no product key, so I cannot install it. The

visual studio 2017 has a key but the key does not work for SQL server

2017. I do not know what to do.

Page 9: Guides for Installing MS SQL Server and Creating Your ...eecs.csuohio.edu/~sschung/cis612/GuideForInstallingMSSQLServerAll… · Either 2012 VS with 2012 SQL Server or 2013 VS with

A: You have to install Visual studio FIRST before installing any SQL Server. You don't need all the

options in VS, don't choose the game, or any extra features, it will take up too much memory if

you include them. You won't see the SQL server option, it is OK.

Another Naïve Client for SQL Server: SQL Command Line How to bring SQL CMD from a Command Line on Window

1. Run CMD 2. Bring SQLCMD with a command as below:

� Sqlcmd –s your_user_id/your_sql_server_name

Page 10: Guides for Installing MS SQL Server and Creating Your ...eecs.csuohio.edu/~sschung/cis612/GuideForInstallingMSSQLServerAll… · Either 2012 VS with 2012 SQL Server or 2013 VS with

Guidelines for Creating a Database USE master;

IF DB_ID('COMPANY') IS NULL CREATE DATABASE COMPANY;

GO

USE COMPANY;

/*

DROP TABLES, SO WE CAN RECREATE THEM */

IF OBJECT_ID('dbo.WORKS_ON') IS NOT NULL

DROP TABLE dbo.WORKS_ON;

IF OBJECT_ID('dbo.DEPT_LOCATIONS') IS NOT NULL

DROP TABLE dbo.DEPT_LOCATIONS;

IF OBJECT_ID('dbo.PROJECT') IS NOT NULL

DROP TABLE dbo.PROJECT;

IF OBJECT_ID('dbo.DEPARTMENT') IS NOT NULL

BEGIN

ALTER TABLE dbo.EMPLOYEE DROP CONSTRAINT FK_EMPLOYEE_DNO; DROP TABLE dbo.DEPARTMENT;

END

IF OBJECT_ID('dbo.DEPENDENT') IS NOT NULL

DROP TABLE dbo.DEPENDENT;

IF OBJECT_ID('dbo.EMPLOYEE') IS NOT NULL DROP TABLE dbo.EMPLOYEE;

GO

Page 11: Guides for Installing MS SQL Server and Creating Your ...eecs.csuohio.edu/~sschung/cis612/GuideForInstallingMSSQLServerAll… · Either 2012 VS with 2012 SQL Server or 2013 VS with

Guidelines for creating a database Creating database scheme Make sure you create all the tables using Create Table statements with all the columns and each PK declared first then add FK using Alter table. Do not mix the FK constraint names with PK, FK column names. To avoid confusion, do not use Constraint names in your DDL, just use Column names of PK, FK with the correct Keywords (clauses) to declare FK. Note that the sequence to create database objects matters here. You should not use any database object (for example, a table name) that you have not created in the database yet inside another table’s DDL. Don't mix the syntax specifying Constraints Name with the syntax without specifying Constraint Name. Use the very specific syntax either with specifying constraint name or without specifying constraint name, NOT a mixture of both syntax, it never going to work. Either one of the following two would be correct. Alter Table Employee Add Foreign Key (Super_ssn) References Employee (Ssn); OR ALTER TABLE EMPLOYEE ADD CONSTRAINT FKCONSTR1 FOREIGN KEY (Super_ssn) REFERENCES EMPLOYEE(Ssn); The typical SQL commands (DML) to populate a table and show the rows inserted into the table

for this task are like the following example.

INSERT INTO EMPLOYEE VALUES('John','B','Smith','123456789','9-Jan-55','731 Fondren,

Houston, TX','M',30000,'987654321',5);

INSERT INTO EMPLOYEE VALUES ('James', 'E', 'Borg', 888665555, '10-Nov-27', '450

Stone, Houston, TX', 'M', 55000, NULL, 1);

Alter Table Employee

Add Foreign Key (Super_ssn) References Employee (Ssn);

Select * From Employee;

insert into DEPARTMENT values ('Headquarters', 1, 888665555, '19-Jun-71');

INSERT INTO DEPENDENT VALUES (123456789, 'Alice', 'F', '31-Dec-78', 'Daughter');

INSERT INTO PROJECT VALUES ('ProductX', 1, 'Bellaire', 5);

INSERT INTO WORKS_ON VALUES (123456789, 1, 32.5);

Page 12: Guides for Installing MS SQL Server and Creating Your ...eecs.csuohio.edu/~sschung/cis612/GuideForInstallingMSSQLServerAll… · Either 2012 VS with 2012 SQL Server or 2013 VS with

ALTER TABLE employee ADD

foreign key (superssn) references employee(ssn),

foreign key (dno) references department(dnumber);

ALTER TABLE department ADD Constraint FKMgrSsnPKSsn

foreign key (mgrssn) references employee(ssn)

Note that the sequence of creating each database object and adding FK constraints matters here. Depends on the sequence you create them, sometimes you might want to populate Employee and Department tables first without adding FK to seed a database with PK before adding a specific FK constraint if the server complaints. Visualize a database ER diagram: It is in the Object Explorer, Click on your Company database, then it will expand the database diagram and all the tables and columns you created under the database. Click database diagram -> ER diagram, then you will see the diagram in the window. If you want to know more on this, check here. http://msdn.microsoft.com/en-us/library/ms189279.aspx

One sequence:

Create all the Tables without FK constraints.

Create Table Employee (

Fname varchar(15) Not Null,

Minit char,

Lname varchar(15) NOT NULL, Ssn char(9) NOT NULL,

Bdate date,

Address varchar(30), Sex char ,

Salary decimal(10,2),

Super_ssn char(9), Dno int NOT NULL

Page 13: Guides for Installing MS SQL Server and Creating Your ...eecs.csuohio.edu/~sschung/cis612/GuideForInstallingMSSQLServerAll… · Either 2012 VS with 2012 SQL Server or 2013 VS with

Primary Key (Ssn),

)

Create Table Department

(

Dname varchar(15) NOT NULL,

Dnumber int NOT NULL, Mgr_ssn char(9) NOT NULL,

Mgr_start_date date

Primary Key (Dnumber),

Unique (Dname),

)

Add ONLY the 5 Tables (Department, Dept_Locations, Project, Works_On, Dependent) with FK, Unique;

Add the 2 FKs of Employee Table later once populate it first to avoid circular reference or refer to other non-existing Table problem;

Alter Table Department

Add Foreign Key (Mgr_ssn) References Employee (Ssn)

2. Populating the COMPANY database using SQL (DML) statements. Comments // 1st, I populating the Table Employee, Insert Into Employee Values ('John', 'B', 'Smith', '123456789','09-Jan-55',

'731 Fondren, Houston, TX', 'M','30000','987654321','5');

Insert Into Employee Values ('Franklin', 'T', 'Wong', '333445555','08-Dec-45',

'638 Voss, Houston, TX', 'M','40000','888665555','5');

2nd, then I populating the Table Department, now FK_Department_Mgr_ssn is valid to point to PK_Employee_Ssn; Insert Into Department Values ('Headquarters','1','888665555','19-Jun-71'); Insert Into Department Values ('Administration','4','987654321','01-Jan-85');

Insert Into Department Values ('Research','5','333445555','22-May-78');

Insert Into Department Values ('Automation','7','123456789','06-Oct-05');

Select * From Department;

Page 14: Guides for Installing MS SQL Server and Creating Your ...eecs.csuohio.edu/~sschung/cis612/GuideForInstallingMSSQLServerAll… · Either 2012 VS with 2012 SQL Server or 2013 VS with

3rd, then I specify the 2 FKs: Super_ssn & Dno of Employee table; Alter Table Employee

Add Foreign Key (Super_ssn) References Employee (Ssn)

Alter Table Employee

Add Foreign Key (Dno) References Department (Dnumber)

4. Populate other tables in order of ( Dept_Locations, Project, Works_On, Dependent)