1.4 MS SQL Server (Database and Schema) - Section - 2
1.4 MS SQL Server (Database and Schema) - Section - 2
KATEB University
Computer Science Department
4th Semester-1401
Subject: RDBMS II
Microsoft SQL Server Management
Lecturer: Rahmatullah Khuram
Unit -4
Database and SCHEMA
char(n) Fixed width character string. Maximum 8,000 characters Defined width
varchar(n) Variable width character string. Maximum 8,000 characters 2 bytes + number of chars
varchar(max) Variable width character string. Maximum 1,073,741,824 characters 2 bytes + number of chars
text Variable width character string. Maximum 2GB of text data 4 bytes + number of chars
nchar Fixed width Unicode string. Maximum 4,000 characters Defined width x 2
numeric(p,s) Fixed precision and scale numbers.Allows numbers from -10^38 +1 to 10^38 –1. 5-17 bytes
The p parameter indicates the maximum total number of digits that can be stored (both to the left and to the right of the decimal point).
p must be a value from 1 to 38. Default is 18.
The s parameter indicates the maximum number of digits stored to the right of the decimal point. s must be a value from 0 to p. Default
value is 0
float(n) Floating precision number data from -1.79E + 308 to 1.79E + 308.The n parameter indicates whether the field should hold 4 or 8 bytes. 4 or 8 bytes
float(24) holds a 4-byte field and float(53) holds an 8-byte field. Default value of n is 53.
datetime From January 1, 1753 to December 31, 9999 with an accuracy of 8 bytes
3.33 milliseconds
datetime2 From January 1, 0001 to December 31, 9999 with an accuracy of 6-8
100 nanoseconds bytes
smalldatetime From January 1, 1900 to June 6, 2079 with an accuracy of 1 4 bytes
minute
date Store a date only. From January 1, 0001 to December 31, 9999 3 bytes
INSERT INTO
dbo.offices(office_name, office_address)
VALUES
('KABUL AFGHANISTAN','400 North 1st
Street, district3, KA 11001'),
('MAZAR AFGHANISTAN','1070 South 2nd
Street, district4, KA 1200');
Then, create a stored procedure that finds office
by office id:
CREATE PROC usp_get_office_by_id(
@id INT
) AS
BEGIN
SELECT
*
FROM
dbo.offices
WHERE
office_id = @id;
END;
After that, transfer this dbo.offices table to the
sales schema:
ALTER SCHEMA sales TRANSFER
OBJECT::dbo.offices;
If you execute the usp_get_office_by_id stored
procedure, SQL Server will issue an error: