Create a New User in SQL Server

This section describes how to create a new login user and grant full permission to a database in SQL Server.

In order to do some tests on PreparedStatement, I created a new login user, "Herong", and granted full permission to "Herong" to use database, AdventureWorks2014:

herong> sqlcmd -S localhost -U sa -P HerongY@ng

1> -- Set AdventureWorks as the current database
2> USE AdventureWorks2014;
3> GO
Changed database context to 'AdventureWorks2014'.

1> -- Create a new server login name: Herong
2> CREATE LOGIN Herong WITH PASSWORD = 'T0pSecret';
3> GO

1> -- Create a new database user linked to the login name
2> CREATE USER Herong FOR LOGIN Herong;
3> GO

1> -- Grant database ALTER permision to the user
2> GRANT ALTER To Herong;
3> GO

1> -- Grant database CONTROL permision to the user
2> GRANT CONTROL To Herong;
3> GO

Here is what I did to test this new login name and user: Herong

herong> sqlcmd -S localhost -U Herong -P TopSecret

1> -- Set AdventureWorks as the current database
2> USE AdventureWorksLT;
3> GO
Changed database context to 'AdventureWorksLT'.

1> -- Create a new table
2> CREATE TABLE Test (ID INT);
3> GO

1> -- Drop the table
2> DROP TABLE Test;
3> GO

Tests looked good to me. New login user, Herong, has enough permission to use database AdventureWorks2014.

Table of Contents

 About This Book

 JDBC (Java Database Connectivity) Introduction

 JDK (Java SE) Installation

 Installing and Running Java DB - Derby

 Derby (Java DB) JDBC Driver

 Derby (Java DB) JDBC DataSource Objects

 Java DB (Derby) - DML Statements

 Java DB (Derby) - ResultSet Objects of Queries

 Java DB (Derby) - PreparedStatement

 MySQL Installation on Windows

 MySQL JDBC Driver (MySQL Connector/J)

 MySQL - PreparedStatement

 MySQL - Reference Implementation of JdbcRowSet

 MySQL - JBDC CallableStatement

 MySQL CLOB (Character Large Object) - TEXT

 MySQL BLOB (Binary Large Object) - BLOB

 Oracle Express Edition Installation on Windows

 Oracle JDBC Drivers

 Oracle - Reference Implementation of JdbcRowSet

 Oracle - PreparedStatement

 Oracle - JBDC CallableStatement

 Oracle CLOB (Character Large Object) - TEXT

 Oracle BLOB (Binary Large Object) - BLOB

 Microsoft SQL Server Express Edition

 Microsoft JDBC Driver for SQL Server

 Microsoft JDBC Driver - Query Statements and Result Sets

 Microsoft JDBC Driver - DatabaseMetaData Object

 Microsoft JDBC Driver - DDL Statements

 Microsoft JDBC Driver - DML Statements

SQL Server - PreparedStatement

Create a New User in SQL Server

 Creating a Table with an IDENTITY Column

 Inserting Rows to the Test Table

 PreparedStatement Overview

 PreparedStatement with Parameters

 PreparedStatement in Batch Mode

 Performance of Inserting Rows with a PreparedStatement

 Performance of Inserting Rows with a Regular Statement

 Performance of Inserting Rows with a ResultSet

 SQL Server CLOB (Character Large Object) - TEXT

 SQL Server BLOB (Binary Large Object) - BLOB

 JDBC-ODBC Bridge Driver - sun.jdbc.odbc.JdbcOdbcDriver

 JDBC-ODBC Bridge Driver - Flat Text Files

 JDBC-ODBC Bridge Driver - MS Access

 JDBC-ODBC Bridge Driver - MS SQL Server

 Summary of JDBC Drivers and Database Servers

 Additional Tutorial Notes to Be Added

 Outdated Tutorials

 References

 Full Version in PDF/EPUB