How to work with tables

Hierarchical and Recursive Queries in SQL Server

Jasmin Ludolf

Content Developer

General SQL statements

  • Create a table
  • Insert data into a table
  • Update fields in a table
  • Drop a table
  • Delete the content of a table
  • Change the structure of a table
Hierarchical and Recursive Queries in SQL Server

Creating a table

General structure:

CREATE TABLE Person(

ID INT NOT NULL, Name CHAR(32) );

Data types:

  • INT representing an integer
  • CHAR representing a string
Hierarchical and Recursive Queries in SQL Server

Insert and update a table

Inserting data:

INSERT INTO ___ VALUES (___, ___);
INSERT INTO Person VALUES ('1', 'Smith');

Updating data:

UPDATE ___ 
    SET ___ = ___ 
    WHERE ___;
UPDATE Person 
    SET Name = 'Anderson' 
    WHERE ID = 1;
Hierarchical and Recursive Queries in SQL Server

Delete and drop a table

Delete the rows of a table:

DELETE FROM ___ 
    WHERE ___;
DELETE FROM Person 
    WHERE ID = 1;

Drop a table:

DROP TABLE ___
DROP TABLE Person
Hierarchical and Recursive Queries in SQL Server

Change a table structure

Add a column:

ALTER TABLE ___ 
    ADD ___ DATATYPE;
ALTER TABLE Person 
    ADD new DATATYPE;

Delete a column:

ALTER TABLE ___ 
    DROP COLUMN ___
ALTER TABLE Person 
    DROP COLUMN old
Hierarchical and Recursive Queries in SQL Server

Let's practice!

Hierarchical and Recursive Queries in SQL Server

Preparing Video For Download...