The Queries in this page solved at the library database. It is a sample database generated by randomly records. You can download it from the link. You will see more than 500 examples in the future. You can filter from the search panel above by selecting sql statements. I hope you will like it

# SQL Insert Examples

##### 1-) Add the writer named Zane Grey to the authors table

Solution 1)

``````Insert into authors
values('x','y')``````

Solution 2)

``````Insert into authors(name,surname)
values('x','y')``````

ETİKETLER

-
##### 2-) Add the student named Ace Collins to the students table

Solution 1)

``````Insert into students
values ('x','y',null,null,null,null)``````

Solution 2)

``````Insert into students(name,surname)
values ('x','y')``````

ETİKETLER

-
##### 3-) Add all authors to the students table

Solution 1)

``````Insert into students(name,surname)
Select name,surname from authors``````

ETİKETLER

- -
##### 4-) Add the writers named Ernest Dowson and Mother Goose to the authors table

Solution 1)

``````Insert into authors(name,surname)
values('Ernest','Dowson'),
('Mother','Goose')``````

Solution 2)

``````Insert into authors
values ('Ernest','Dowson'),
('Mother','Goose')``````

ETİKETLER

-
##### 5-) Add the male students from class "9b" to the authors table

Solution 1)

``````Insert into authors(name,surname)
select name,surname from students
where sinif='9A' and gender='M'``````

Solution 2)

``````Insert into authors
select name,surname from students
where sinif='9A' and gender='M'``````

ETİKETLER

- - -
##### 6-) Insert into the authors table, Random selected five students

Solution 1)

``````Insert into authors(name,surname)
Select top 5 name,surname from students order by newid()``````

ETİKETLER

- - - -
##### 7-) Add the authors whose name contains "a" character from autors table to students table. The class of autors will have been '12M'

Solution 1)

``````Insert into students(name,surname,sinif)
Select name,surname,'12M' from authors where name like '%a%'``````

ETİKETLER

- - -
##### 8-) Generate Unique Random Numbers In Sql With Stored Procedure

Solution 1)

``````Create procedure randomGenerate(@unit int,@min int,@max int)
as
Begin
Declare @numbers table(number int)
Declare @i int = 0
Declare @number int
while (@i<@unit)
Begin
Set @number = floor(rand()*(@max-@min+1))+@min
if(not exists(Select * from @numbers where number = @number))
begin
insert into @numbers values(@number)
Set @i = @i + 1
end
end
Select * from @numbers order by 1
End
--To Execute Stored Procedure
Execute randomGenerate 5,20,30``````

ETİKETLER

- - - -
Library Database