Skip to content

Commit 6ed5fc9

Browse files
authored
Add files via upload
add file
1 parent 5caa5b0 commit 6ed5fc9

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

AUTO INCREMENT in SQL.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Auto increment
2+
-> Auto increment is used to generate an unique number when a new record is inserted into a table.
3+
ex:create table staff ( s_id int(10) NOT NULL AUTO_INCREMENT,name varcha
4+
r (50), number int (10),PRIMARY KEY (s_id) );
5+
Query OK, 0 rows affected, 2 warnings (0.01 sec)
6+
7+
mysql> desc staff;
8+
+--------+-------------+------+-----+---------+----------------+
9+
| Field | Type | Null | Key | Default | Extra |
10+
+--------+-------------+------+-----+---------+----------------+
11+
| s_id | int | NO | PRI | NULL | auto_increment |
12+
| name | varchar(50) | YES | | NULL | |
13+
| number | int | YES | | NULL | |
14+
+--------+-------------+------+-----+---------+----------------+
15+
16+
ex: INSERT INTO staff(name,number) VALUES ('Hari',4567890);
17+
mysql> select * from staff;
18+
+------+------+---------+
19+
| s_id | name | number |
20+
+------+------+---------+
21+
| 1 | Hari | 4567890 |
22+
+------+------+---------+

NOT NULL in SQL.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// NOT NULL
2+
-> By default a tables column can hold NULL values.
3+
The NOT NULL constraint enforces a field to always contain a vlaue. This means that you cannot insert a new record, or update a record without
4+
adding a value to this field.
5+
ex:create table example(name varchar (30),roll int (10), number int(10)
6+
NOT NULL);
7+
8+
// output
9+
desc example;
10+
+--------+-------------+------+-----+---------+-------+
11+
| Field | Type | Null | Key | Default | Extra |
12+
+--------+-------------+------+-----+---------+-------+
13+
| name | varchar(30) | YES | | NULL | |
14+
| roll | int | YES | | NULL | |
15+
| number | int | NO | | NULL | |
16+
+--------+-------------+------+-----+---------+-------+
17+
18+
msg : INSERT INTO example (name,roll) VALUES('Ram',10);
19+
ERROR 1364 (HY000): Field 'number' doesn't have a default value
20+
mysql>

PRIMARY KEY in SQL.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// PRIMARY Key
2+
-> The PRIMARY KEY constraint uniquely identifies each record in a database table.
3+
Primaray keys must contains UNIQUE values. A primary key column cannot contain NULL values.
4+
Most tables should have a primary key, and each table can have only ONE primary key.
5+
syntax: CREATE TABLE example(s_id int (10) NOT NULL PRIMARY KEY ,name varchar
6+
(50), roll_no int (10) ,number int (10));
7+
8+
ex: desc example;
9+
+---------+-------------+------+-----+---------+-------+
10+
| Field | Type | Null | Key | Default | Extra |
11+
+---------+-------------+------+-----+---------+-------+
12+
| s_id | int | NO | PRI | NULL | |
13+
| name | varchar(50) | YES | | NULL | |
14+
| roll_no | int | YES | | NULL | |
15+
| number | int | YES | | NULL | |
16+
+---------+-------------+------+-----+---------+-------+

UNIQUE KEY in SQL.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// UNIQUE Key
2+
-> The UNIQUE constraint uniquely identifies each record in a database table.
3+
There can be many UNIQUE constraints per table. A Unique key column can contain NULL values.
4+
ex: CREATE TABLE example(s_id int (10) UNIQUE ,name varchar(50), roll_no
5+
int (10) UNIQUE ,number int (10));
6+
7+
output:desc example;
8+
+---------+-------------+------+-----+---------+-------+
9+
| Field | Type | Null | Key | Default | Extra |
10+
+---------+-------------+------+-----+---------+-------+
11+
| s_id | int | YES | UNI | NULL | |
12+
| name | varchar(50) | YES | | NULL | |
13+
| roll_no | int | YES | UNI | NULL | |
14+
| number | int | YES | | NULL | |
15+
+---------+-------------+------+-----+---------+-------+
16+
17+
ex: insert into example (s_id,name,number) VALUES(2,'RAM',9888888);
18+
mysql> select * from example;
19+
+------+------+---------+---------+
20+
| s_id | name | roll_no | number |
21+
+------+------+---------+---------+
22+
| 1 | RAM | 1 | 9888888 |
23+
| 2 | RAM | NULL | 9888888 |
24+
+------+------+---------+---------+

0 commit comments

Comments
 (0)