Posts

Showing posts from January, 2024

Session : 2 : Creating and querying part of a table

CREATE TABLE  use TESTOUT_DB go create table tbl_Employee  ( Employee_Number varchar(20), Employee_FirstName varchar(20), Employee_MiddleName varchar(20), Employee_LastName varchar(20), Employee_Government varchar(20), Data_of_Birth date ) Second one  use TESTOUT_DB go create table tbl_Employee_1 ( Employee_Number varchar(20) NOT NULL, Employee_FirstName varchar(20) NOT NULL, Employee_MiddleName varchar(20) NULL,  -- you can have a blank for a middle name Employee_LastName varchar(20) NOT NULL, Employee_Government INT NOT  NULL, Data_of_Birth date ) 57 : ADDING ADDITIONAL TABLE

T-SQL - Docs - Link

 https://learn.microsoft.com/en-us/sql/t-sql/language-reference?view=sql-server-ver16

T-SQL String Data Types and Function

Image
 Substring NULL Another way to do the same thing. declare @firstname as nvarchar(20) declare @middlename as nvarchar(20) declare @lastname as nvarchar(20) set @firstname = 'Wakka' set @middlename = 'Cassa' set @lastname = 'Booba' --select  select @firstname + CASE WHEN @middlename IS NULL THEN '' ELSE ' ' + @middlename END + ' ' + @lastname as FullName CONCAT  41 : Joining a String to a number:  The number 3456 is converted to varchar below. select 'This is the name of the unit: ' + convert(varchar(20), 3456) select 'This is the name of the unit: ' + convert(varchar(20), 3456) as UnitCol select 'This is the name of the unit: ' + cast(4567 as varchar(20)) as Cast_Col Converting to Pound sterling  France Currency : DATA DATA TYPES 48 : Today's Date and More date function :  Converting date back to strings 

T-SQL : Number Types and Function

Image
 USE keyword to ensure that the correct database is been used, Declare a variable DECLAR @myvar as int = 2 or  DECLAR @myvar as int set @myvar = 2 select @myvar as myvariale tested below DECLARE @myvar as int = 2 select @myvar as my_variable; int datatype truncates anything that comes after decimal.

T-SQL - Page 1 : Download and Install & Creating Tables , Retrieving , and deleting

Image
Creating a Database :  Databases --> Right click -- Give a DB Name Creating our first query SELECT 1+100  SELECT 1+100 as TOTAL SELECT 1+100  SELECT 8+10 as TOTAL Batch   GO tells this is end of the batch ,  Creating a Table  There are two ways to create a Table  -- first one by using a Graphical User Interface or GUI --  Creating Table using T-SQL Inserting into Tables using T-SQL The caps lock for the table is the only acepting one for me whereas in the tutorial it is accepting caps and small create table tblfirst (FirstName varchar (200) ) INSERT INTO TBLFIRST VALUES ('Elephant') The intellisense which the SQL server relies on hasn't been updated. or Ctl+Shift + R Inserting values in any way Retrieving Data  select FirstName from tblfirst; to show everything below, this time i dragged the table. select * from [dbo].[tblfirst];   select * from [tblfirst];  // dbo is optional we can take that away Deleting...