Main menu

MSSQL Developement : Basic Transact-SQL Query

CREATE DATABASE WinDB;

EXEC sp_databases;

USE WinDB;

CREATE TABLE WinDBUsers (id int, name varchar(20), email varchar(20));

EXEC sp_tables ;

SELECT * FROM sys.tables;

EXEC sp_columns WinDBUsers;

ALTER TABLE WinDBUsers ALTER COLUMN name nvarchar(100);
ALTER TABLE WinDBUsers ADD lastname varchar(20);

INSERT INTO WinDBUsers VALUES (1, ‘zoladius’, ‘zolan@sector19.net’);

INSERT INTO WinDBUsers VALUES
(1, ‘zoladius’, ‘zolan@sector19.net’)
(2, ‘marina’, marina@sector19.net’)
(3, ‘hardith’, ‘hardith@sector19.net’)
(4, ‘jack’, ‘jack@sector19.net’);

SELECT name, email FROM WinDBUsers;

SELECT * FROM WinDBUsers;

SELECT * FROM WinDBUsers ORDER BY name DESC;
SELECT * FROM WinDBUsers ORDER BY name ASC;

SELECT * FROM WinDBUsers WHERE id=3;TSQL logical operators
SELECT * FROM WinDBUsers WHERE id<3;
SELECT * FROM WinDBUsers WHERE id>3;
SELECT * FROM WinDBUsers WHERE id<5 AND id>3;
SELECT * FROM WinDBUsers WHERE id<3 OR id>3;

DROP TABLE WinDBUsers;

DROP DATABASE WinDB;

 

 

 

 

FacebookTwitterGoogle+RSS