Data Definition and Data Types

Slides:



Advertisements
Similar presentations
Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands.
Advertisements

MySQL-Database Teppo Räisänen Oulu University of Applied Sciences School of Business and Information Management.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
Database Management System LICT 3011 Eyad H. Elshami.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
SQL Data Definition Language (DDL) Using Microsoft SQL Server 1SDL Data Definition Language (DDL)
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
Using SQL Connecting, Retrieving Data, Executing SQL Commands, … Svetlin Nakov Technical Trainer Software University
Fox MIS Spring 2011 Database Week 6 ERD and SQL Exercise.
Data Modeling Creating E/R Diagrams SoftUni Team Technical Trainers Software University
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
Sets, Dictionaries SoftUni Team Technical Trainers Software University
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
SQL Server for Developers Using SQL Server, DB Design, SQL SELECT, INSERT, UPDATE, DELETE SoftUni Team Technical Trainers Software University
Stacks and Queues Processing Sequences of Elements SoftUni Team Technical Trainers Software University
XML Processing SoftUni Team Database Applications Technical Trainers
Auto Mapping Objects SoftUni Team Database Applications
Static Members and Namespaces
Introduction to Entity framework
Databases basics Course Introduction SoftUni Team Databases basics
C# Basic Syntax, Visual Studio, Console Input / Output
C# Basic Syntax, Visual Studio, Console Input / Output
Introduction to MVC SoftUni Team Introduction to MVC
Deploying Web Application
Introduction to Entity Framework
Mocking tools for easier unit testing
Parsing JSON JSON.NET, LINQ-to-JSON
State Management Cookies, Sessions SoftUni Team State Management
EF Code First (Advanced)
PHP MVC Frameworks MVC Fundamentals SoftUni Team Technical Trainers
Database Design and Rules
EF Relations Object Composition
Entity Framework: Code First
Parsing XML XDocument and LINQ
Managing Tables, Data Integrity, Constraints by Adrienne Watt
MySQL-Database Jouni Juntunen Oulu University of Applied Sciences
Databases advanced Course Introduction SoftUni Team Databases advanced
Install and configure theme
Entity Framework: Relations
Fast String Manipulation
Functional Programming
Processing Variable-Length Sequences of Elements
Databases Advanced Course Introduction SoftUni Team Databases Advanced
Best practices and architecture
How to connect natively?
Introduction to Databases
Arrays and Multidimensional Arrays
Built-in Functions. Usage of Wildcards
Data Definition and Data Types
Multidimensional Arrays, Sets, Dictionaries
Extending functionality using Collections
Exporting and Importing Data
Functional Programming
C# Advanced Course Introduction SoftUni Team C# Technical Trainers
Exporting and Importing Data
CSS Transitions and Animations
Train the Trainers Course
Hibernate (JPA) Code First Entity Relations
Spring Data Advanced Querying
Text Processing and Regex API
/^Hel{2}o\s*World\n$/
CSS Transitions and Animations
SQL data definition using Oracle
CS122 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
Data Definition Language
Data Definition Language
CS122 Using Relational Databases and SQL
SQL (Structured Query Language)
Presentation transcript:

Data Definition and Data Types Managing DBs using IDEs Databases Basics SoftUni Team Technical Trainers SQL Software University http://softuni.bg © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

Table of Contents Common data types Creating a database using MySQL / MSSQL Creating a table using MySQL / MSSQL Dropping table using MySQL / MSSQL Altering a table using MySQL / MSSQL Filling a table using MySQL / MSSQL Truncating a table using MySQL / MSSQL © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

Questions sli.do #5604

Common Data Types Data type SQL Server MySQL Boolean BIT TINYINT Integer INT Floating-point FLOAT FLOAT, Double String(fixed) CHAR(n) NCHAR(n) String (variable) VARCHAR(n) NVARCHAR(n) Binary Object BINARY(n) (fixed up to 8K) VARBINARY(n) (<8K) VARBINARY(max) (>8K & < 2G) BINARY(n) VARBINARY(n) Date DATE DATETIME bit (Transact-SQL) An integer data type that can take a value of 1, 0, or NULL. The SQL Server Database Engine optimizes storage of bit columns. If there are 8 or less bit columns in a table, the columns are stored as 1 byte. If there are from 9 up to 16 bit columns, the columns are stored as 2 bytes, and so on. The string values TRUE and FALSE can be converted to bit values: TRUE is converted to 1 and FALSE is converted to 0. MySQL: you can use bool and boolean which are at the moment aliases of tinyint(1). A value of zero is considered false. Non-zero values are considered true. MSSQL: char is with fixed size and cannot store Unicode symbols. If the length of the entered sequence is less. MSSQL: varchar is with flexible size but similar to char on all other criteria. MSSQL char/varchar – additional info https://msdn.microsoft.com/en-us/library/ms176089.aspx MSSQL nchar/nvarchar – almost identical to char/varchar but with the difference that you can put Unicode symbols and therefor each one of them take more space. MySQL: char is very similar to the char of MSSQL, but it can hold Unicode symbols. If the entered value is shorter than the size of the char(n), the rest is filled with spaces which are truncated when retrieved. The entered value is trimmed from trailing spaces, so ‘aa ’ results in ‘aa’ when retrieved. MySQL: varchar is very similar to the nvarchar of MSSQL. It does not trim trailing white spaces of a value. MySQL: char/varchar – additional info http://dev.mysql.com/doc/refman/5.7/en/char.html MSSQL: binary/varbinary – analog of char/varchar, but for saving data as plain bytes MSSQL: binary/varbinary – additional info https://msdn.microsoft.com/en-us/library/ms188362.aspx MySQL: binary/varbinary - analog of the char/varchar, but for saving data as bytes MYSQL: binary/varbinary – additional info http://dev.mysql.com/doc/refman/5.7/en/binary-varbinary.html MYSQL: blob – differs very slightly from varbinary by the following things: There is no trailing-space removal for BLOB when values are stored or retrieved. BLOB columns cannot have DEFAULT values. © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

Creating Database

MySQL Using HeidiSQL

SQL Server Using SSMS

Creating Tables

MySQL Using HeidiSQL CREATE TABLE table_name ( id INT NOT NULL, name VARCHAR(50) NOT NULL, age INT )

SQL Server Using SSMS Ctrl + S CREATE TABLE TableName ( Id INT NOT NULL, Name VARCHAR(50) NOT NULL, Age INT ) Ctrl + S

Adding Primary Key

MySQL Using HeidiSQL CREATE TABLE table_name ( P_Id int NOT NULL, PRIMARY KEY (P_Id) )

SQL Server Using SSMS Right click the wanted column CREATE TABLE TableName ( P_Id int NOT NULL PRIMARY KEY )

Adding auto increment MySQL SQL Server CREATE TABLE Persons ( ID int NOT NULL AUTO_INCREMENT, ) CREATE TABLE Persons ( ID int IDENTITY PRIMARY KEY )

Adding check constraint MySQL SQL Server CREATE TABLE table_name ( P_Id INT, CHECK (P_Id>0) ) CREATE TABLE TableName ( P_Id INT CHECK (P_Id>0) )

Adding default value MySQL SQL Server CREATE TABLE table_name ( City varchar(255) DEFAULT 'Sandnes' ) CREATE TABLE TableName ( City varchar(255) DEFAULT 'Sandnes' )

Set unique field MySQL SQL Server CREATE TABLE table_name ( P_Id INT, UNIQUE (P_Id) ) CREATE TABLE TableName ( P_Id INT UNIQUE )

Dropping Tables

MySQL Using HeidiSQL DROP TABLE table_name

SQL Server Using SSMS DROP TABLE TableName

Dropping primary keys

MySQL Using HeidiSQL ALTER TABLE table_name DROP PRIMARY KEY

SQL Server Using SSMS Right click the wanted column ALTER TABLE TableName DROP CONSTRAINT ConstraintName

Dropping check constraint MySQL SQL Server ALTER TABLE table_name DROP CHECK check_name ALTER TABLE TableName DROP CONSTRAINT check_name

Dropping default value MySQL SQL Server ALTER TABLE table_name ALTER column_name DROP DEFAULT ALTER TABLE TableName ALTER COLUMN ColumnName DROP DEFAULT

Drop unique field MySQL SQL Server ALTER TABLE table_name DROP INDEX constraint_name ALTER TABLE TableName DROP CONSTRAINT ConstraintName

Dropping Database

MySQL Using HeidiSQL DROP DATABASE database_name

SQL Server Using SSMS DROP DATABASE DatabaseName

Altering Tables and Columns

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

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

Altering table and adding primary keys

MySQL/SQL Server ALTER TABLE table_name ADD PRIMARY KEY (column(s)) ALTER TABLE table_name ADD CONSTRAINT constrant_name PRIMARY KEY (column(s))

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)

Adding default value on alter table MySQL SQL Server ALTER TABLE table_name ALTER column_name SET DEFAULT default_value ALTER TABLE TableName ALTER COLUMN ColumnName SET DEFAULT DefaultValue

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))

Inserting and Selecting Data

Click the plus and enter data Using HeidiSQL Click the plus and enter data

Using SSMS

Truncating Data

Erasing Data TRUNCATE TABLE People

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.

Data Definition and Data Types https://softuni.bg/courses/ © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

License This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International" license Attribution: this work may contain portions from "Databases" course by Telerik Academy under CC-BY-NC-SA license © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

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 © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.