Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using SQL Server through Command Prompt

Similar presentations


Presentation on theme: "Using SQL Server through Command Prompt"— Presentation transcript:

1 Using SQL Server through Command Prompt
Lab 3 Database Engineering

2 Connecting to SQL Server
Command: Sqlcmd –S Computername\instanceName.

3 Create New Login Create login user_name with password = ‘password';
Use GO statement to execute the query

4 Server level roles

5 Grant privileges To add server role:
EXEC sp_addsrvrolemember ‘user_name', ‘server_role';

6 Create User for specific database
USE database_name CREATE USER [User_name] FOR LOGIN [login_name]

7 Database Level Role

8 Grant privileges to the user
EXEC sp_addrolemember, ‘database_role’ ‘user_name’

9 Creating database Command: Create database database_name

10 Opening specific database
Command: Sqlcmd –S Computername\instanceName -d database- Name

11 Create table Command: create table table_name (column_name datatype, column_name datatype) Table with primary key

12 Supported data types in SQL server

13 Composite primary key 1> CREATE TABLE Customer ( 2> FirstName VARCHAR(15), 3> LastName VARCHAR (15), 4> CONSTRAINT pkey PRIMARY KEY (FirstName, LastName)

14 Index An index is a copy of selected columns of data from a table that can be searched very efficiently that also includes a low- level disk block address or direct link to the complete row of data it was copied from

15 Create index Create index index_name ON table_name (column-name)

16 Insert values into the table
Insert into table_name values (value1, value2)

17 Select statement Select * from Table_Name

18 Using input file Sqlcmd –S Computername\instanceName – d database-name -i inputfile_path

19 Using input and output files
Sqlcmd –S Computername\instanceName – d database-name -i input_filepath – o output_filepath

20 Directly run Query Note: using capital Q will run the query and exit SQLCMD

21 EXIT SQLCMD To end the sqlcmd session, type EXIT at the sqlcmd prompt.

22 Exercise Let's assume you are designing a flight reservation system. At its simplest, the application requires database tables for the flights, the customers, and the reservations. 1) Create the database and required tables using SQLCMD. Note: All tables should have primary key. Use composite primary key for customer table

23 Exercise 2) Create login for the server and give privileges of system administrator to it. 3) Create two users account for your database. Give the privileges of Database owner and read only to them. 4) Login with the user having privilege of database owner 5) Insert at least five records in each table 6) Create index for the flight and reservation table’s column .

24 Exercise 7) Show all tables data in command prompt
8) Write the select query for all created tables in script file and execute it through SQLCMD 9) Save the output of the select queries in output files using SQLCMD 10) Run direct query for selecting columns of tables in SQLCMD.


Download ppt "Using SQL Server through Command Prompt"

Similar presentations


Ads by Google