Logo/
Kaaif Ahmed

Shared by Kaaif Ahmed

Log in

Make a lecture like this from your own PDF

Drop a PDF, slides or notes here. You'll sign up, then yours starts.

0:00 / 3:08

0:00 / 3:08Getting Started with SSMS
SQL Server Management and T-SQL Fundamentals
Kaaif Ahmed

Shared by Kaaif Ahmed

Summary

Full transcript

0:00Welcome to our SQL Server lab. We begin in SQL Server Management Studio, or SSMS. First, launch the application and connect to your Database Engine. Once connected, use the New Query button to open a workspace. It is vital to use the 'USE' command at the start of your scripts to ensure you are working in the correct database context. We will also use the GO keyword to separate batches, allowing multiple commands to execute in sequence.

0:29Let's look at the basic lifecycle of a table. We start with 'CREATE TABLE' to define our structure. To add data, we use 'INSERT INTO' followed by our values. We can view our results using 'SELECT asterisk', and if we need to change a specific record, the 'UPDATE' statement with a 'WHERE' clause is our tool. Finally, 'DELETE' removes specific rows, while 'DROP TABLE' removes the table entirely from the database. Always check the Messages pane for error numbers and line references if a command fails.

1:01In Session B, we build a robust 'course' database with an 'academic' schema. We will create eight related tables, including departments, students, and enrollments. Choosing the right data type is critical: use NVARCHAR for names to support Unicode, DATE or DATETIME2 for schedules, and DECIMAL for precise values. For identifiers and counts, we use INTEGER, TINYINT, or BIGINT depending on the required scale. This foundation ensures data integrity across the entire academic system.

1:36Requirements often change after a table is created. We use 'ALTER TABLE' with the 'ADD' keyword to insert new columns, or 'ALTER' to change a column's data type. If you need to rename a column, SQL Server uses the 'sp_rename' system stored procedure. We can also add 'DEFAULT' constraints to ensure columns have a value even when one isn't provided during insertion. Finally, 'DROP COLUMN' allows us to prune unnecessary data structures.

2:07When clearing data, 'TRUNCATE TABLE' is faster than delete but keeps the structure. When removing tables, watch out for dependencies. You cannot drop a parent table if a child table still references it; you'll see a dependency error. The correct order is to drop child tables like 'enrollments' first, then move up to parents. For more robust scripts, use 'DROP TABLE IF EXISTS'. This prevents your script from crashing if a table has already been removed.

2:38Your final challenge is creating a master script. This single file should drop all objects in the correct order, recreate the database and schema, and rebuild all tables. This level of automation is essential for professional database management. Remember to submit your T-SQL scripts, query outputs, and error logs as your lab deliverables. With these skills, you're ready to manage complex SQL Server environments. Happy coding!

Ask AI about this video

Answers cite the source. Free account, no credit card.