0% found this document useful (0 votes)
27 views

SQL Coomand

The document discusses various SQL commands and clauses for working with databases and tables. It explains how to create and delete databases, use databases, and create tables within databases. It also covers SQL constraints like primary keys, foreign keys, and check constraints. Finally, it discusses common clauses like where, limit, and order by for filtering and sorting query results.

Uploaded by

Ram pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

SQL Coomand

The document discusses various SQL commands and clauses for working with databases and tables. It explains how to create and delete databases, use databases, and create tables within databases. It also covers SQL constraints like primary keys, foreign keys, and check constraints. Finally, it discusses common clauses like where, limit, and order by for filtering and sorting query results.

Uploaded by

Ram pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

How to create database in sql

CREATE DATABASE db_name;

2. How to delete database

DROP DATABASE db_name

3. How to use database

USE db_name

4. Creating table in database

CREATE TABLE table_name(

col_name1 datatype constraint,

col_name2 datatype constraint

);

----------DATABASE RELATED QUERIES---------

CREATE DATABASE IF NOT EXISTS db_name;

DROP DATABASE IF EXISTS db_name;

SHOW DATABASES;

SHOW TABLES;

---------TABLE RELATED QUERIES-------------

SELECT * FROM table_name;

INSERT INTO table_name

(col1,col2)

VALUES

(col1_V1,col2_V2),

(col1_v2,col2_V2);
----------CONSTRAINTS---------

SQL CONSTRAINTS ARE USED TO SPECIFY RULES FOR DATA IN TABLE.

NOT NULL ---> columns cannot have a null value

UNIQUE -----> all values in column are diffrent

PRIMARY KEY --> all values in column are unique and not null

DEFAULT ---> set the default values of a column

ex-> salary INT DEFAULT 25000

-----PRIMARY KEY SYNTAX ----

CREATE TABLE temp(

id INT,

rollno INT NOT NULL,

PRIMARY KEY(id)

);

-----CONSTRAINTS CHECK ----

CREATE TABLE city(

id INT PRIMARY KEY,

city VARCHAR(50),

age INT,

CONSTAINT age_check CHECK (age >=20 AND city = "DELHI")

); ^

it can be ignored or it can by written


----------FORIGEN KEY CONSTRAINT-----------

CREATE TABLE temp (

cust_id INT,

FORIGN KEY (cust_id) REFERENCES customer(id)

);

-----------WHERE CLAUSE------------

TO DEFINE SOME CONDITIONS

SELECT * FROM table_name WHERE CONDITIONS;

EX- SELECT * FROM student WHERE marks > 80;

- SELECT * FROM student WHERE city = "Mumbai";

OPERATORS

AND (to check for both conditons to be true)

SELECT * FROM student WHERE marks > 80 AND city = "Mumbai";

OR (to check for one of the conditions to be true)

SELECT * FROM student WHERE marks > 90 OR city = "Mumbai";

BETWEEN(selects for a given range)

SELECT * FROM student WHERE marks BETWEEN 80 AND 90;

IN (matches any value in the list)

SELECTS * FROM student WHERE city IN("DELHI","MUMABI");

NOT IN(to negate the given condition)


SELECT * FROM student WHERE city NOT IN("DELHI", "MUMBAI")

---------------------LIMIT CLAUSE----------------

Sets an upper limit on number of (tuples) rows to be returned

SELECT * FROM student LIMIT 3;

----------------------ORDER BY CLAUSE-----------

to sort in ascending (ASC) or decending order (DESC);

SELECT * FROM student ORDER BY city ASC;

You might also like