LEARN SQL: PART-1
First we will understand some important points in sql like data,schema,database,tables etc…
What is data?
A data can be facts related to any object in this world.
Ex: a person can have name, phone no, birthdate, gender etc.
What is database?
- Database means to store information about a business. It a systematic collection of data so it is easy for everyone to update, managed, access.
- For ex: SQL (Structured Query Language) is a standard computer language for relational database management and data manipulation. SQL is used to query, insert, update and modify data. SQL store data in rows and columns form called table.
- There are four system databases in SQL server: master, model, tempdb, msdb.
Syntax to create database:
Create database database_name;
Command to list all exiting databases in SQL server:
Select name as database_name from sys.databases where database_id >4;
- We have choose a database before creating table in SQL . the table will be created in the specified database.
Syntax for selecting database.
What is schema?
- We use schema to group objects together. It provides security and logical ordering of objects. When we are creating table and not provide schema name then SQL use dbo schema by default, which is there for the database owner.
Syntax to create schema:
Create schema ;
What is Table?
- A table in sql is defined as collection of rows and columns. columns in sql is also called attribute and rows called tuple. Each row in the table must contain unique data.
Syntax to create table:
Create or alter table schema.table_name
Col_name1 datatype(size) NULL/NOT NULL,
Col_name2 datatype(size) NULL/NOT NULL
- The meaning of NULL means missing value. If NULL is specified in the column then it allow null value. If NOT NULL is specified then column not allow null value.
Create Database information;
Create Schema HR; –schema HR is created
Create or alter table HR.Employee –create table Employee in HR schema
eid int NOT NULL,
- In above example we create information database using create database statement. Then we used this created database using use information statement here information is our database name. Then we created a schema HR using create schema statement. Then we create a Employee table in information database using HR schema. The columns of the tables are eid, ename, age, phoneno.
For SQL Constraint see my next post learn-sql-part-2 . If you have any question related to this post then comment us.
Keep Visiting TechwithR.com for more upcoming top technical articles.