Download SQL Server

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Data Definition and
Data Types
Managing DBs using IDEs
SoftUni Team
Technical Trainers
Software University
http://softuni.bg
Table of Contents
1. Common data types
2. Creating a database using MySQL / MSSQL
3. Creating a table using MySQL / MSSQL
4. Dropping table using MySQL / MSSQL
5. Altering a table using MySQL / MSSQL
6. Filling a table using MySQL / MSSQL
7. Truncating a table using MySQL / MSSQL
2
Questions
sli.do
#5604
3
Common Data Types
Data type
SQL Server
MySQL
Boolean
Integer
Floating-point
String(fixed)
BIT
INT
FLOAT
CHAR(n)
NCHAR(n)
VARCHAR(n)
NVARCHAR(n)
BINARY(n) (fixed up to 8K)
VARBINARY(n) (<8K)
VARBINARY(max) (>8K & < 2G)
DATE
DATETIME
TINYINT
INT
FLOAT, Double
CHAR(n)
String (variable)
Binary Object
Date
VARCHAR(n)
BINARY(n)
VARBINARY(n)
DATE
DATETIME
4
5
MySQL
Using HeidiSQL
6
SQL Server
Using SSMS
7
8
MySQL
Using HeidiSQL
CREATE TABLE table_name
(
id INT NOT NULL,
name VARCHAR(50) NOT NULL,
age INT
)
9
SQL Server
CREATE TABLE TableName
(
Id INT NOT NULL,
Name VARCHAR(50) NOT NULL,
Age INT
)
Using SSMS
Ctrl + S
10
11
MySQL
Using HeidiSQL
CREATE TABLE table_name
(
P_Id int NOT NULL,
PRIMARY KEY (P_Id)
)
12
SQL Server
Using SSMS
Right click the wanted column
CREATE TABLE TableName
(
P_Id int NOT NULL PRIMARY KEY
)
13
Adding auto increment
MySQL
CREATE TABLE Persons
(
ID int NOT NULL AUTO_INCREMENT,
)
SQL Server
CREATE TABLE Persons
(
ID int IDENTITY PRIMARY KEY
)
14
Adding check constraint
MySQL
CREATE TABLE table_name
(
P_Id INT,
CHECK (P_Id>0)
)
SQL Server
CREATE TABLE TableName
(
P_Id INT CHECK (P_Id>0)
)
15
Adding default value
MySQL
CREATE TABLE table_name
(
City varchar(255) DEFAULT 'Sandnes'
)
SQL Server
CREATE TABLE TableName
(
City varchar(255) DEFAULT 'Sandnes'
)
16
Set unique field
MySQL
CREATE TABLE table_name
(
P_Id INT,
UNIQUE (P_Id)
)
SQL Server
CREATE TABLE TableName
(
P_Id INT UNIQUE
)
17
18
MySQL
Using HeidiSQL
DROP TABLE table_name
19
SQL Server
Using SSMS
DROP TABLE TableName
20
Dropping primary keys
21
MySQL
Using HeidiSQL
ALTER TABLE table_name
DROP PRIMARY KEY
22
SQL Server
Using SSMS
Right click the wanted column
ALTER TABLE TableName
DROP CONSTRAINT
ConstraintName
23
Dropping check constraint
MySQL
ALTER TABLE table_name
DROP CHECK check_name
SQL Server
ALTER TABLE TableName
DROP CONSTRAINT check_name
Dropping default value
MySQL
ALTER TABLE table_name
ALTER column_name DROP DEFAULT
SQL Server
ALTER TABLE TableName
ALTER COLUMN ColumnName DROP DEFAULT
25
Drop unique field
MySQL
ALTER TABLE table_name
DROP INDEX constraint_name
SQL Server
ALTER TABLE TableName
DROP CONSTRAINT ConstraintName
26
27
MySQL
Using HeidiSQL
DROP DATABASE
database_name
28
SQL Server
Using SSMS
DROP DATABASE
DatabaseName
29
30
MySQL
Using HeidiSQL
Add column:
ALTER TABLE table_name
ADD column_name VARCHAR(50)
Delete column:
ALTER TABLE table_name
DROP COLUMN column_name
Modify type of column:
ALTER TABLE table_name
MODIFY COLUMN column_name datatype
31
SQL Server
Using SSMS
Add column:
ALTER TABLE TableName
ADD ColumnName VARCHAR(50)
Delete column:
ALTER TABLE TableName
DROP COLUMN ColumnName
Modify type of column:
ALTER TABLE TableName
ALTER COLUMN ColumnName datatype
32
Altering table and adding
primary keys
33
MySQL/SQL Server
ALTER TABLE table_name
ADD PRIMARY KEY (column(s))
ALTER TABLE table_name
ADD CONSTRAINT constrant_name PRIMARY KEY (column(s))
34
Adding check constraint on altering table
MySQL/SQL Server
ALTER TABLE Persons
ADD CHECK (check condition)
ALTER TABLE Persons
ADD CONSTRAINT check_name CHECK (check condition)
35
Adding default value on alter table
MySQL
ALTER TABLE table_name
ALTER column_name SET DEFAULT
default_value
SQL Server
ALTER TABLE TableName
ALTER COLUMN ColumnName SET DEFAULT
DefaultValue
36
Adding unique field on alter table
MySQL/SQL Server
ALTER TABLE TableName
ADD UNIQUE (column(s))
ALTER TABLE TableName
ADD CONSTRAINT unique_constraint_name UNIQUE (column(s))
37
38
Using HeidiSQL
Click the plus and
enter data
39
Using SSMS
40
41
Erasing Data
TRUNCATE TABLE People
42
Summary
 We can create and modify or delete databases or tables using the
SQL language version in either SQL Server
and MySQL.
 We can easily fill data into our database
using the IDE for the corresponding
technology and later, see the data from the
tables.
43
Data Definition and Data Types
?
https://softuni.bg/courses/
License
 This course (slides, examples, demos, videos, homework, etc.)
is licensed under the "Creative Commons AttributionNonCommercial-ShareAlike 4.0 International" license
 Attribution: this work may contain portions from

"Databases" course by Telerik Academy under CC-BY-NC-SA license
45
Free Trainings @ Software University
 Software University Foundation – softuni.org
 Software University – High-Quality Education,
Profession and Job for Software Developers

softuni.bg
 Software University @ Facebook

facebook.com/SoftwareUniversity
 Software University @ YouTube

youtube.com/SoftwareUniversity
 Software University Forums – forum.softuni.bg
Related documents