Download presentation
Presentation is loading. Please wait.
Published byClifford Doland Modified over 9 years ago
1
1 SQL Server Management Studio SQL DDL CREATE TABLE Constraints ALTER TABLE DROP TABLE The GUI way Steen Jensen, autumn 2013
2
A lot of the time you will be working in the Query window Most of the commands can be executed in a graphical way, but start training typing in the SQL commands The management studio is huge and a lot of functionality is aimed for administrators And now for a live demo! 2
3
SQL stands for Structured Query Language and can be divided into two groups of commands: DDL: Data Definition Language for handling the structure DML: Data Manipulation Language for handling the content In SQL Server Management Studio you will be using a dialect of SQL called T-SQL (Transact SQL), which is largely compliant with ANSI/ISO SQL standards All queries work on objects – a fully qualified object name: [ServerName.[DatabaseName.[SchemaName.]]]ObjectName A schema can be used for separating database objects into logical groups – default schema = dbo (= database owner) An object name must always be part of a query – the rest are optional 3
4
The command CREATE TABLE is used to create a table and have the below general structure: 4
5
Identity: SQL Server automatically assigns a sequenced number for every inserted/new row (other DBMS’s calls this “auto_increment”) Seed is the start value, and increment how much it should be increased Computed columns: Used for derived attributes/columns Column constraints: Covered in chapter 6 (e.g. Primary key) 5
6
Selected rules for table & column names: Capitalization: start each word with a capital letter (“camel casing”) Name length: keep names as short as possible Limit abbreviations: only use well-known abbreviations (e.g. “no” ) Eliminate spacing between words: use camel casing Avoid underscore : “tricky” to type, difficult to read (underline) 6
7
7
8
8
9
9
10
10
11
The below create command creates a table called Employees 11
12
Different constraints can be added for a table Primary key constraints: 12
13
Foreign key constraints: 13
14
Foreign key constraints – self-referencing: 14
15
Unique constraints: Often referred as alternate keys 15
16
Check constraints: Can make a lot of validation 16
17
Below is a little subset of, what is possible using the check constraint 17
18
Default constraints: If a value is supplied in an insert, then no default value will be used If no value is supplied in an insert, then the default value will be used 18
19
Continue with your Amazon system and create the necessary tables in SQL Server Management Studio 19
20
The command ALTER TABLE is used to change an existing table and have the below general structure: 20
21
The below figure shows two examples of adding new fields/columns to an existing table: 21
22
The command DROP TABLE is used to delete the structure and the content of an existing table: 22
23
Instead of typing in SQL commands you can do it in a graphical way Try this by following the instructions page 165bot – 170bot 23
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.